追逐我的尾巴试图找到一个很好的例子来说明如何用地方细节填充信息窗口。
我的情景是:
我找到了几个例子,但似乎没有一个适合我:
Google Maps Places api, how do I get the standard infowindow content from a marker https://developers.google.com/maps/documentation/javascript/examples/places-placeid-finder
https://developers.google.com/maps/documentation/javascript/places
https://developers.google.com/maps/documentation/javascript/examples/place-details
这是我的代码的链接,我希望有人能指引我,我迷失了......
https://github.com/smartcookiemedia/google-maps-script/blob/master/google-maps.js
答案 0 :(得分:1)
例如,您可以在单击标记时查找地点详细信息。
要做到这一点
您应该将suppressInfoWindows设置为true
var layer = new google.maps.KmlLayer(baseurl + kml[id].url, {
preserveViewport: true,
suppressInfoWindows: true
});
将点击监听器添加到图层
layer.addListener('click', function(kmlEvent) {
var request = {
location: kmlEvent.latLng,
radius: '10',
name: kmlEvent.featureData.name
};
service.nearbySearch(request, callback);
});
并使回调函数看起来像这样
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
var place = results[0];
infowindow.setContent(place.name + ' ' + place.place_id);
infowindow.setPosition(place.geometry.location);
infowindow.open(map);
}
}
结果将如下所示