简体   繁体   中英

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. 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. Also I get the right lat and lang values when I do a alert(..).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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