簡體   English   中英

如何將Google地圖集中到緯度和經度位置?

[英]How to center a Google Map to a latitude and longitude location?

請考慮以下代碼:

$('.stores').click(function() {
    console.log($(this).data('latitude'));  // -1754.26265626
    console.log($(this).data('longitude')); // 65.262518
    console.log(themap); // Properly a Google Map instance.

    themap.setCenter(new LatLng($(this).data('latitude'), $(this).data('longitude')));
});

根據文檔 ,我可以使用setCenter方法輕松地將地圖居中,但我不理解文檔正在使用的符號。

看到:

LatLng(lat:number, lng:number, noWrap?:boolean)

我究竟如何使用它?

我收到錯誤:

Uncaught ReferenceError: LatLng is not defined 

你必須使用

themap.setCenter(new google.maps.LatLng($(this).data('latitude'), $(this).data('longitude')));

所有Google Maps javascript類均使用google.maps.ClassName()表示法引用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM