您可以获取公交车站名称、ID 和坐标,然后使用任何其他 API 获取有关公交车站的信息。这是代码:
var overlay;
overlay = new google.maps.OverlayView();
overlay.draw = function() {};
overlay.setMap(map);
$('#map-canvas').click(function(event){
var point = new google.maps.Point(event.pageX,event.pageY);
var location = overlay.getProjection().fromContainerPixelToLatLng(point); //get map coordinates by click
var request = {
location: location,
types: ['bus_station','subway_station'], //get bus stops and metro stations
radius: 10,
};
placesService = new google.maps.places.PlacesService(map);
placesService.search(request, function(result, status, pagination){
station = result[0];
if(typeof station != 'undefined'){
pos = station.geometry['location']; //position
bus_no = station.name.match(/\[([0-9]+)\]/i)[1]; //get ID by name
alert(bus_no); // ID
}
});
});