0

所以,我一直在尝试减小我在谷歌地图中使用的自定义标记的大小。我确实找到了一些与减小大小相关的属性,即https://developers.google.com/maps/documentation/javascript/reference/marker#Icon

但是,尽管我尝试它不会反映。那么,你能帮我确定我在哪里做错了吗?

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);

因此,希望能在指出错误方面提供一些帮助。谢谢。

这是当前的图标大小

4

2 回答 2

2
<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}  
/>

找到了丢失的单词。它的new

于 2018-12-27T12:30:03.723 回答
0

通过使用比例,我们减小了图标的大小。

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>
于 2018-12-27T10:30:26.580 回答