简体   繁体   English

Google Maps api json ajax-标记未显示

[英]Google maps api json ajax — markers not showing up

I have coded the part where I fetch the JOSN of markers and iterate through them. 我已经对获取标记的JOSN并对其进行迭代的部分进行了编码。 But for some reason the markers are not showing up on map. 但是由于某些原因,标记未显示在地图上。 Can someone help me find the mistake. 有人可以帮我找到错误。

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

I have already defined the map variable, latLng and marker. 我已经定义了地图变量latLng和marker。 Also I get the right lat and lang values when I do a alert(..). 当我执行alert(..)时,我也会获得正确的lat和lang值。

Thanks 谢谢

Why are you converting to string. 为什么要转换为字符串。

The Constructor Documentation 构造器文档

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

Change 更改

latLng = new google.maps.LatLng(JSON.stringify(place.lat), JSON.stringify(place.lng)); 

To

latLng = new google.maps.LatLng(place.lat,place.lng); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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