[英]Google maps api json ajax — markers not showing up
我已經對獲取標記的JOSN並對其進行迭代的部分進行了編碼。 但是由於某些原因,標記未顯示在地圖上。 有人可以幫我找到錯誤。
$.ajax({
url: "get_markers.php",
type: 'POST',
dataType: 'json',
data: {'address':address},
success: function (html, status, response) {
$.each(html, function(i, place) {
alert(JSON.stringify(place.lat)+","+JSON.stringify(place.lng));
latLng = new google.maps.LatLng(JSON.stringify(place.lat), JSON.stringify(place.lng));
marker = new google.maps.Marker({
position: latLng,
map: map
//title: data.title
});
});
}
我已經定義了地圖變量latLng和marker。 當我執行alert(..)時,我也會獲得正確的lat和lang值。
謝謝
為什么要轉換為字符串。
構造器文檔
LatLng(lat:number, lng:number, noWrap?:boolean)
更改
latLng = new google.maps.LatLng(JSON.stringify(place.lat), JSON.stringify(place.lng));
至
latLng = new google.maps.LatLng(place.lat,place.lng);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.