Convert lat,lng into Address and show on infoWindow google map api

最后都变了- 提交于 2019-12-25 03:36:09

问题


I have list of lat, lng values in object

var path = [{"lat":"12.9247903824","lng":"77.5806503296"},{"lat":"10.9974470139","lng":"76.9459457397"}]

Here i have to convert latlng into address and have to show marker and infowindow. Address have to be shown in info window

I have tried this one, i have getting address and multiple markers but i not able to show address on info windows.. last infowindow only showing address

for (var i = 0; i < path.length; i++) {
    var pos = new google.maps.LatLng(path[i]["lat"], path[i]["lng"]);

    var marker = new google.maps.Marker({
        position: pos,
        map: map
    });

    geocoder.geocode({'latLng': pos}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            infowindow.setContent(results[i].formatted_address);
        } else {
            alert('Geocoder failed due to: ' + status);
        }
    });
}

回答1:


Do you have a listener to open the infowindow when you click a marker? Insert the geocoder function inside that listener, do the geocode, set content to the infowindow and then open the infowindow.



来源:https://stackoverflow.com/questions/31201337/convert-lat-lng-into-address-and-show-on-infowindow-google-map-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!