gpt4 book ai didi

javascript - Google map API - 格式化的电话号码在侧栏列表中显示为未定义

转载 作者:行者123 更新时间:2023-12-03 12:05:18 24 4
gpt4 key购买 nike

我正在尝试在乘车侧栏上显示地点及其电话号码的列表。当我单击标记时,电话号码可以工作,但在侧栏中显示为未定义。任何帮助都非常感谢。

   $(document).ready(function(){  

var map = null;
var gmarkers = [];
var service = null;
var infowindow = new google.maps.InfoWindow({size: new google.maps.Size(150,50)});

function initialize() {
var slo = new google.maps.LatLng(35.2742, -120.6631);

map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: slo,
zoom: 11
});

service = new google.maps.places.PlacesService(map);

var request = {
location: slo,
radius: 30000,
types: ['hospital']
};
infowindow = new google.maps.InfoWindow();
service.nearbySearch(request, callback);
}

function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}

function createMarker(place) {
var placeLoc = place.geometry.location;
if (place.icon) {
var image = new google.maps.MarkerImage(
place.icon, new google.maps.Size(71, 71),
new google.maps.Point(0, 0), new google.maps.Point(17, 34),
new google.maps.Size(25, 25));
} else var image = null;

var marker = new google.maps.Marker({
map: map,
icon: image,
position: place.geometry.location
});
var request = {
reference: place.reference
};

google.maps.event.addListener(marker,'click',function(){
service.getDetails(request, function(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
var contentStr = '<h5>'+place.name+'</h5><p>'+place.formatted_address;
if (!!place.formatted_phone_number) contentStr += '<br>'+place.formatted_phone_number;
if (!!place.website) contentStr += '<br><a target="_blank" href="'+place.website+'">'+place.website+'</a>';
contentStr += '<br>'+place.types+'</p>';
infowindow.setContent(contentStr);
infowindow.open(map,marker);
} else {
var contentStr = "<h5>No Result, status="+status+"</h5>";
infowindow.setContent(contentStr);
infowindow.open(map,marker);
}
});

});
gmarkers.push(marker);
var side_bar_html = "<a href='javascript:google.maps.event.trigger(gmarkers["+parseInt(gmarkers.length-1)+"],\"click\");'>"+place.name+"-"+place.formatted_phone_number+"</a><br>";
document.getElementById('side_bar').innerHTML += side_bar_html;
}

google.maps.event.addDomListener(window, 'load', initialize);



});

最佳答案

信息窗口中显示的格式化电话号码在 placeDetails response 中返回,当单击标记时会发生这种情况,它在 nearbySearch response 中不可用。 ,用于创建侧边栏。

关于javascript - Google map API - 格式化的电话号码在侧栏列表中显示为未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25214835/

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