0

您能帮我弄清楚如何在信息窗口(或列表)中获取巴士站的名称,如下图所示?

在此处输入图像描述

我正在使用 Google Maps Api 3 示例中的这个示例,它列出了所有公交车站,但它只是获得了站点的标题。这是代码

var map;
var infowindow;

function initialize() {
var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316);

map = new google.maps.Map(document.getElementById('map-canvas'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 15
});

var request = {
 location: pyrmont,
 radius: 500,
 types: ['store']
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
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;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});

 google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
 }

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

此代码有效,但正如我所说,它只是列出了停靠点的名称:

在此处输入图像描述

感谢您的意见

4

0 回答 0