2013-04-18 34 views
1

我已经编码了部分,我获取标记的JOSN并遍历它们。但由于某些原因,标记没有显示在地图上。有人能帮我找到这个错误吗?谷歌地图api json ajax - 标记不显示

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

我已经定义了map变量latLng和marker。当我做一个警报(..)时,我也可以得到正确的经纬度值。

谢谢

回答

1

你为什么要转换为字符串。

Constructor文档

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);