Google Maps Api v3 - map.panTo causing “too much recursion”

前端 未结 1 1295
醉梦人生
醉梦人生 2021-01-23 09:41

I\'m having a problem finishing off my script, it works using map.setCenter to reposition on each marker, but I would like to pan to each new marker. However, when I use the pan

相关标签:
1条回答
  • 2021-01-23 10:24

    One reason for this problem are undefined variables lat and lng at the beginning of initialize() method:

    function initialize() {
    
        latlng = new google.maps.LatLng(lat, lng);
    
        mapOptions = {
        ...
    

    lat and lng have to be defined to some values. For example:

    function initialize() {
        lat = 47.89;
        lng = 13.45;
    
        latlng = new google.maps.LatLng(lat, lng);
        ...
    

    The other problem is that at the end of code there is a call:

    google.maps.event.addDomListener(window, 'load', initialize);
    

    which should be commented out.

    0 讨论(0)
提交回复
热议问题