Google maps - keep center when zooming

后端 未结 4 1546
渐次进展
渐次进展 2021-02-07 10:21

In Google Maps, I would like to be able to keep the center of the map on a marker on my location when I\'m zooming in or out. It\'s something that Ingress does, it doesn\'t matt

4条回答
  •  爱一瞬间的悲伤
    2021-02-07 11:13

    You should try the center_changed event with panTo function.

    google.maps.event.addListener(mymap, 'center_changed', function() {
        mymap.panTo({lat: myLoc.lat, lng: myLoc.lon});
    })
    

    You can see an example about it here and documentation about panTo function here. Becareful, it should mess up all the draggable thing.

提交回复
热议问题