在Google Map API中检索公交线路或地铁的详细信息 [英] Retrieve details on Bus Line or Subway in Google Map API
问题描述
我正在寻找像这样的网站: WEBSITE GMAPS 目前我可以在500米左右获得所有东西,就像是巴士站或其他东西,但我无法检索公交线路。
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();
service.search(request,callback);
function function callback(results,status){
if(status == google.maps.places.PlacesServiceStatus.OK){
$ scope.placesTransit = [];
$ scope.timeTotal = [];
angular.forEach(results,function(result,key){
var timeTotal;
directionsService.route(
{
origin:new google.maps.LatLng( $ scope.map.center.latitude,$ scope.map.center.longitude),
destination:result.geometry.location,
travelMode:google.maps.DirectionsTravelMode.WALKING,
unitSystem :google.maps.UnitSystem.METRIC
},函数(响应,状态)
{
if(status == google.maps.DirectionsStatus.OK)
{
result.timeTotal = response.routes [0] .legs [0] .duration.text;
if(result.types [0] ===subway_station){
result .typeTransport =Métro;
}
console.log(result);
$ scope.placesTransit.push(result);
}
});
});
$ b如果有人能帮助我如何做到:
显然,我可以通过 page ,但Google MAP API v3没有任何功能。任何想法 ?谢谢
是的,Google有一个地方可以获取有关公共交通的信息。
首先,您需要检查您的城市是否受支持: href =https://maps.google.com/landing/transit/cities/ =nofollow> https://maps.google.com/landing/transit/cities/
然后,如果支持,您可以在这里获得更多信息:
要以编程方式访问它,您可以同时使用以下API:
- https://developers.google.com/transit/
- https://developers.google.com / maps / documentation / directions /
我会选择第二个。
考虑到这一点,如果您正试图检查的公司已注册,您将可以轻松访问其所有公交路线(以及更多)。
p>如果公司没有列出,那么这意味着他们在地图上编码了路径,并且必须使用叠加层来完成相同的操作。
希望它有帮助!
I'm looking for doing something like this website : WEBSITE GMAPS
For the moment i can get everything around 500meters like if it's a bus stop or something else but i can't retrieve the Bus line.
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();
service.search(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;
directionsService.route(
{
origin: new google.maps.LatLng($scope.map.center.latitude, $scope.map.center.longitude),
destination: result.geometry.location,
travelMode: google.maps.DirectionsTravelMode.WALKING,
unitSystem: google.maps.UnitSystem.METRIC
}, function (response, status)
{
if (status == google.maps.DirectionsStatus.OK)
{
result.timeTotal = response.routes[0].legs[0].duration.text;
if (result.types[0] === "subway_station") {
result.typeTransport = "Métro";
}
console.log(result);
$scope.placesTransit.push(result);
}
});
});
}
}
If someone can helps me how to do that : Apparently i can retrieve this information on this page , but there's nothing to get this with Google MAP API v3 . Any Idea ? Thanks
Yes, Google has a place where you can get the information about public transportation.
First, you need to check if your city is supported:
Then, if it is supported you can get more information here:
To access it programatically, you can both the following APIs:
I would go with the second one.
With this in mind, if the company you are trying to check is registered, you will be able to easily access all of its bus routes (and more).
If the company is not listed however, it means that they coded the path on the map that you see, and you must do the same using overlays:
Hope it helps!
这篇关于在Google Map API中检索公交线路或地铁的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!