帮助查找,如何在信息窗口中显示动态地址(单击标记时) 我必须包括纬度和经度,但是由于循环,它只为所有标记显示一个地址,但是在这里,我需要为单个标记显示特定地址
var infoWindow = new google.maps.InfoWindow();
var geocoder;
var map;
var i,j;
var js_lats = ['11.798880','13.0826802','12.975444'];
var js_longs =['77.827760','80.2707184','80.220642'];
if(js_lats.length>0)
{
for (i = 0; i < js_lats.length; i++) {
var latlng = new google.maps.LatLng(js_lats[i],js_longs[i]);
var geocoder = geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
loc= results[1].formatted_address;
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 10
}
var geocode = document.getElementById('address1').value;
map = new google.maps.Map(document.getElementById('dvMap'), mapOptions);
geocoder = new google.maps.Geocoder();
document.getElementById("dis").setAttribute('style','visibility:visible;');
geocoder.geocode( { 'address': loc},
function(results, status)
{
map.fitBounds(results[0].geometry.viewport);
var icon = "Markers/letter_m.png";
var infoWindow = new google.maps.InfoWindow();
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
var loc1 = loc;
(function (marker){
google.maps.event.addListener(marker, "click", function (e) {{
infoWindow.setContent("<span class='lm_loc_detail_trk'>Location :</span><span class='lm_addr_detail_trk'>"+loc1+ "</span></div>");
infoWindow.open(map, marker);
}});})(marker);
var listener = google.maps.event.addListener(map, "idle", function () {
map.setZoom(6);
google.maps.event.removeListener(listener);
});
}
else{alert('Geocode was not successful for the following reason: ' + status);
}
});}}});}}