Gaurav Kumar
Gaurav Kumar

Reputation: 1231

How to reduce the size of custom icon of marker in google-maps-react?

So, I have been trying to reduce the size of my custom marker used in google maps. I did find some property related to reducing the size i.e https://developers.google.com/maps/documentation/javascript/reference/marker#Icon

But, as much I try it won't reflect. So, can u help me identify where am I doing something wrong?

import React, { Component } from 'react';
import { Map, Marker, GoogleApiWrapper } from 'google-maps-react';
import logo from './pins/Minigrid_RMS_Absent.png'
const mapStyles = {
  width: '100%',
  height: '100%'
};

export class MapContainer extends Component {
  constructor(props){
  super(props)
  this.onMarkerClick=this.onMarkerClick.bind(this)
}
onMarkerClick(){
  console.log('called:')
}
render() {
return (
  <Map
    google={this.props.google}
    zoom={5}
    style={mapStyles}
    initialCenter={{
     lat: 21.5937,
     lng: 78.9629
    }}
  >
  <Marker key='0' icon={{
    url: logo,
    scaledSize:  this.props.google.maps.Size(15,25)
  }} position={{lat: 21.5937, lng: 78.9629}} onClick={this.onMarkerClick}  
/>
  </Map>
);
}
}

export default GoogleApiWrapper({
 apiKey: 'MYKEY'
})(MapContainer);

So, would appreciate some help in pointing the mistake. Thanks.

Here is the current icon size

Upvotes: 2

Views: 12155

Answers (2)

Gaurav Kumar
Gaurav Kumar

Reputation: 1231

<Marker key='0' icon={{
url: logo,
scaledSize:  new this.props.google.maps.Size(15,25)
}} position={{lat: 21.5937, lng: 78.9629}} onClick={this.onMarkerClick}  
/>

Found the missing word. Its new

Upvotes: 3

AishuSuhan P
AishuSuhan P

Reputation: 123

By using scale, we reduce the size of an icon.

import { withGoogleMap, GoogleMap, Marker } from "react-google-maps";

 var iconPin = {
        path: 'M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z',
        fillColor: '#64be67',
        fillOpacity: 1,
        scale: 0.05, //to reduce the size of icons
       };


 <GoogleMap zoom={3}>
    <Marker key={marker.id}
            position={{ lat: marker.latitude, lng: marker.longitude}}
            icon={iconPin} />
 </GoogleMap>

Upvotes: 0

Related Questions