Google maps api 3 如何在谷歌地图API中获取起点和终点之间路线上的位置(如加油站)
您能告诉我是否有可能在谷歌地图API中获得所有地点的列表,例如起点和终点之间路线上的加油站?这是一个链接,我试图列出两点之间的所有加油站或休息区(或谷歌地图API支持的任何地点类型),基于支持方向的路线 到目前为止,这是我的代码:Google maps api 3 如何在谷歌地图API中获取起点和终点之间路线上的位置(如加油站),google-maps-api-3,Google Maps Api 3,您能告诉我是否有可能在谷歌地图API中获得所有地点的列表,例如起点和终点之间路线上的加油站?这是一个链接,我试图列出两点之间的所有加油站或休息区(或谷歌地图API支持的任何地点类型),基于支持方向的路线 到目前为止,这是我的代码: var directionsDisplay; var directionsService = new google.maps.DirectionsService(); var map; var haight = new google.maps.LatLng(49.21
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var haight = new google.maps.LatLng(49.216364,-122.811897);
var oceanBeach = new google.maps.LatLng(50.131446,-119.506838);
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: haight
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
calcRoute();
}
function calcRoute() {
var request = {
origin: haight,
destination: oceanBeach,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
编辑部分:
// Make the directions request
directionService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsRenderer.setDirections(result);
// Box around the overview path of the first route
var path = result.routes[0].overview_path;
var boxes = routeBoxer.box(path, distance);
drawBoxes(boxes);
} else {
alert("Directions query failed: " + status);
}
for (var i = 0; i < boxes.length; i++) {
var bounds = box[i];
// Perform search over this bounds
}
});
}
//发出指示请求
路由(请求、功能(结果、状态){
if(status==google.maps.directionstatus.OK){
directionsRenderer.setDirections(结果);
//第一条路线的概览路径周围的框
var path=result.routes[0]。概述\u路径;
变量框=路由框(路径、距离);
抽屉(盒);;
}否则{
警报(“方向查询失败:+状态”);
}
对于(变量i=0;i
var-map=null;
var-boxpolys=null;
var方向=null;
var routeBoxer=null;
变量距离=null;//公里
var服务=null;
var gmarkers=[];
var-box=null;
var infowindow=new google.maps.infowindow();
函数初始化(){
//默认地图视图为美国大陆。
变量映射选项={
中心:新google.maps.LatLng(40,-80.5),
mapTypeId:google.maps.mapTypeId.ROADMAP,
缩放:8
};
map=new google.maps.map(document.getElementById(“map”)、mapOptions);
服务=新的google.maps.places.PlacesService(地图);
routeBoxer=新的routeBoxer();
directionService=new google.maps.directionService();
directionsRenderer=新建google.maps.directionsRenderer({
地图:地图
});
//如果URL末尾有任何参数,它们将位于location.search中
//看起来像“?标记=3”
//跳过第一个字符,我们对“”不感兴趣
var query=location.search.substring(1);
//在每个“&”字符处拆分其余字符,以给出“argname=value”对的列表
var pairs=query.split(“&”);
对于(变量i=0;i0)
request.types=type.split(',');
其他的
request.types=[type];
}
if(!!关键字&&(关键字!=“”))request.keyword=关键字;
if(!!name&&(name!=“”))request.name=name;
service.nearbySearch(请求、功能(结果、状态){
if(status==google.maps.places.PlacesServiceStatus.OK){
document.getElementById('side_bar')。innerHTML+=“bounds[“+searchIndex+”]返回“+results.length+”结果
”
for(变量i=0,结果;结果=结果[i];i++){
var marker=createMarker(结果);
}
}否则{
document.getElementById('side_bar')。innerHTML+=“bounds[“+searchIndex+”]返回0个结果
status=“+status+”
”;