gpt4 book ai didi

javascript - 谷歌地图 :Displaying address in infowindow

转载 作者:行者123 更新时间:2023-11-28 09:37:54 25 4
gpt4 key购买 nike

我正在尝试实现信息窗口并在其中显示地址..下面是我的代码

    $('#citiesdata').empty(); 

var listFavourite = [];

$(responce).find("favorite").each(function() {
var name = $(this).find("name").text();
var address = $(this).find("address").text();
var phoneNo = $(this).find("phoneNo").text();
var lattitude = $(this).find("lattitude").text();
var longitude = $(this).find("longitude").text();

var favouriteObject = new Object();
favouriteObject.name = name;
favouriteObject.address = address;
favouriteObject.lattitude = lattitude;
favouriteObject.longitude = longitude;
listFavourite.push(favouriteObject);

$('#citiesdata').append('<tr><td><b>'+name+'</b></td></tr>');
$('#citiesdata').append('<tr><td>'+address+'</td></tr>');
$('#citiesdata').append('<tr><td>'+phoneNo+'</td></tr>');



});
//call map service to load map with marker
//method name(listFavourite);
var content = "<div id='tabs'>"+
"<form id='button'>"+
"<div>"+
"<input type='button' value='click me' onclick='alert(\"infoWindow\")'>"+
"</div>"+
"</form>"+
"</div>";

var map = new google.maps.Map(document.getElementById("map_canvas"), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
});
var infowindow = new google.maps.InfoWindow({
//content: content
});

for (var n = 0 ; n <listFavourite.length ; n++)
addMarker(listFavourite[n]);
}


function addMarker(data) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data.lattitude, data.longitude),
map: map,
title: data.address
});
google.maps.event.addListener(marker, "click", function() {
infowindow.setContent(data.address);
infowindow.open(map, marker);
});

};

这里我从数组列表中获取数据(地址)..我想在信息窗口中显示该地址..谢谢

最佳答案

您需要在单独的函数中创建标记:

for (var n = 0 ; n <listFavourite.length ; n++)
addMarker(listFavourite[n]);
}


function addMarker(data) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data.lattitude, data.longitude),
map: map,
title: data.address
});
google.maps.event.addListener(marker, "click", function() {
infowindow.setContent(data.address);
infowindow.open(map, marker);
});

};

关于javascript - 谷歌地图 :Displaying address in infowindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12776511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com