问题
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