【发布时间】:2016-06-14 15:00:25
【问题描述】:
这里的原始问题: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);
}
});
});
}
}
【问题讨论】:
-
有人可以帮助我吗? :S
标签: angularjs google-maps google-maps-api-3