2012-12-18 38 views
3

考慮下面的代碼:如何將Google地圖放置到經緯度位置?

$('.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'))); 
}); 

按照documentation,我可以使用setCenter方法,輕鬆地地圖中心,但我不明白的文檔所使用的符號。

參見:

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

究竟如何我用這個?

,我發現了錯誤:

Uncaught ReferenceError: LatLng is not defined 

回答

7

你必須使用

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

JavaScript類與google.maps.ClassName()符號

+0

當然涉及到的所有谷歌地圖!這是有道理的,因爲在全球範圍內**沒有** LatLng對象。 D'哦! – sergserg

相關問題