Adding Marker to Google Maps in google-map-react

前端 未结 4 1477
耶瑟儿~
耶瑟儿~ 2020-12-14 15:53

I am using the google-map-react NPM package to create a Google Map and several markers.

Question: How can we add the default Google Maps markers to

4条回答
  •  春和景丽
    2020-12-14 16:08

    This may not be entirely clear from the description in the Readme, but the maps argument is, in fact, the maps API object (and map is, of course, the current Google Map instance). Therefore, you should pass both to your method:

    onGoogleApiLoaded={({map, maps}) => this.renderMarkers(map, maps)}
    

    and use them:

    renderMarkers(map, maps) {
      let marker = new maps.Marker({
        position: myLatLng,
        map,
        title: 'Hello World!'
      });
    }
    

提交回复
热议问题