0
ORIGINAL的問題在這裏:Retrieve details on Bus Line or Subway in Google Map API如何獲得公交線路或地鐵十號線(第2後)
我有一個位置(緯度,經度),我想找到此位置附近的公交線路或地鐵線。 這PAGE給我的地鐵名稱/行,但與谷歌地方的API,我無法檢索信息。
我使用了方向服務,但它不像預期的那樣工作。方向多段線是好的,但我仍然不能訪問公交線路站或地鐵名稱...
任何想法?
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);
}
});
});
}
}
有人能幫助我嗎? :S –