繁体   English   中英

Google Maps api json ajax-标记未显示

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM