此处的原始问题:Retrieve details on Bus Line or Subway in Google Map API
我有一个位置(lat,lng),我想在这个位置附近找到公交线路或地铁线路。 这个PAGE给了我地铁名称/行,但是使用google places API,我无法检索信息。
我使用了DirectionServices,但它没有按预期工作。方向折线还可以,但我仍然无法访问公交线路站或地铁名称......
有什么想法吗?
var mapControl = $scope.map.control.getGMap();
service = new google.maps.places.PlacesService(mapControl);
var transitLayer = new google.maps.TransitLayer();
transitLayer.setMap(mapControl);
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(mapControl);
service.nearbySearch(request, callback);
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
$scope.placesTransit = [];
$scope.timeTotal = [];
angular.forEach(results, function(result, key) {
var timeTotal;
console.log(result);
directionsService.route(
{
origin: new google.maps.LatLng($scope.map.center.latitude, $scope.map.center.longitude),
destination: result.name,
travelMode: google.maps.TravelMode.TRANSIT,
}, function (response, status)
{
if (status == google.maps.DirectionsStatus.OK)
{
directionsDisplay.setDirections(response);
result.timeTotal = response.routes[0].legs[0].duration.text;
if (result.types[0] === "subway_station") {
result.typeTransport = "Métro";
}
$scope.placesTransit.push(result);
}
});
});
}
}
答案 0 :(得分:0)
UP post(不知道我是否可以这样做)