【问题标题】:Google Maps: setCenter and panTo not working谷歌地图:setCenter 和 panTo 不工作
【发布时间】:2012-10-03 18:12:52
【问题描述】:

我有以下 Google Maps v3 JS 代码来更改当前地图中心位置:

//current map center:40.714409999999994,-74.00598000000004 (New York, NY)

    //destination map center: 40.765789515305165,-80.32365839672855 Beaver Falls, PA
    var latLng = new google.maps.LatLng(40.765789515305165,-80.32365839672855);
    console.log('center b4:');
    console.log(VZ.MDU.Map.map.getCenter());
    VZ.MDU.Map.map.setCenter(latLng);
    console.log('center after:');
    console.log(VZ.MDU.Map.map.getCenter());

问题是,当我调用 setCenter 时;地图不会改变位置;它仍然显示纽约市中心而不是宾夕法尼亚州比弗福尔斯。当我在调用 .setMap 之前和之后调用 map.getCenter 时;在 map.setCenter 调用之后,中心保持不变。我也尝试过 panTo,但这也无济于事。我没有收到任何 JS 错误,只是不会更改地图位置。

感谢任何有用的建议。

【问题讨论】:

    标签: javascript google-maps-api-3


    【解决方案1】:

    有一个问题。您在最后一次调用 setCeter 时没有传递任何内容(在 console.log 中)。我将它们更改为字符串。 改变了

    //current map center:40.714409999999994,-74.00598000000004 (New York, NY)
    
        //destination map center: 40.765789515305165,-80.32365839672855 Beaver Falls, PA
        var latLng = new google.maps.LatLng(40.765789515305165,-80.32365839672855);
        console.log('center b4:');
        console.log("VZ.MDU.Map.map.getCenter()");
        VZ.MDU.Map.map.setCenter(latLng);
        console.log('center after:');
        console.log("VZ.MDU.Map.map.getCenter()");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-17
      • 1970-01-01
      相关资源
      最近更新 更多