简体   繁体   English

在不使用地图的情况下使用Google Maps api获取方向

[英]get direction with google maps api without using a map

Hi I'm playing around with a frontend project which will have no backend and I want it to get transit direction from a specific place to another. 嗨,我正在玩一个没有后端的前端项目,我希望它获得从特定位置到另一个位置的运输方向。

The problem I have is that google maps api for browser does always have to use a map if I'm correct. 我的问题是,如果我正确的话,用于浏览器的Google Maps API总是必须使用地图。

I just want to show eg 3 next bus from this bus stop. 我只想显示例如从该巴士站出发的3辆下一班车。

It so much documentation on different things and I'm not sure which api to use. 关于不同事物的文档太多了,我不确定要使用哪个api。 Could I use server api? 我可以使用服务器api吗?

Any google api pro out there who could help me? 有没有可以帮助我的Google API专业人士?

thanks! 谢谢!

A map is not required. 不需要地图。 The Google Maps Javascript API v3 DirectionsService can just render the text directions in the "panel" (an HTML div). Google Maps Javascript API v3 DirectionsService只能在“面板”(HTML div)中呈现文本方向。

From the documentation : 文档中

setPanel(panel:Node) | setPanel(panel:Node)| Return Value: None This method renders the directions in a . 返回值:无此方法在中显示方向。 Pass null to remove the content from the panel. 传递null以从面板中删除内容。

code snippet: (modified from this example in the documentation ) 代码段:(文档中的此示例修改)

 function initMap() { var directionsDisplay = new google.maps.DirectionsRenderer; var directionsService = new google.maps.DirectionsService; directionsDisplay.setPanel(document.getElementById('right-panel')); var onChangeHandler = function() { calculateAndDisplayRoute(directionsService, directionsDisplay); }; document.getElementById('start').addEventListener('change', onChangeHandler); document.getElementById('end').addEventListener('change', onChangeHandler); calculateAndDisplayRoute(directionsService, directionsDisplay); } function calculateAndDisplayRoute(directionsService, directionsDisplay) { var start = document.getElementById('start').value; var end = document.getElementById('end').value; directionsService.route({ origin: start, destination: end, travelMode: google.maps.TravelMode.TRANSIT }, function(response, status) { if (status === google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } else { window.alert('Directions request failed due to ' + status); } }); } google.maps.event.addDomListener(window, "load", initMap); 
 html, body { height: 100%; margin: 0; padding: 0; } 
 <script src="https://maps.googleapis.com/maps/api/js"></script> <div id="floating-panel"> <strong>Start:</strong> <select id="start"> <option value="chicago, il">Chicago</option> <option value="st louis, mo">St Louis</option> <option value="joplin, mo">Joplin, MO</option> <option value="oklahoma city, ok">Oklahoma City</option> <option value="amarillo, tx">Amarillo</option> <option value="gallup, nm">Gallup, NM</option> <option value="flagstaff, az">Flagstaff, AZ</option> <option value="winona, az">Winona</option> <option value="kingman, az">Kingman</option> <option value="barstow, ca">Barstow</option> <option value="san bernardino, ca">San Bernardino</option> <option value="los angeles, ca">Los Angeles</option> </select> <br> <strong>End:</strong> <select id="end"> <option value="chicago, il">Chicago</option> <option value="st louis, mo" selected="selected">St Louis</option> <option value="joplin, mo">Joplin, MO</option> <option value="oklahoma city, ok">Oklahoma City</option> <option value="amarillo, tx">Amarillo</option> <option value="gallup, nm">Gallup, NM</option> <option value="flagstaff, az">Flagstaff, AZ</option> <option value="winona, az">Winona</option> <option value="kingman, az">Kingman</option> <option value="barstow, ca">Barstow</option> <option value="san bernardino, ca">San Bernardino</option> <option value="los angeles, ca">Los Angeles</option> </select> </div> <div id="right-panel"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在不显示谷歌地图的情况下获取并显示方向 - Get and show direction without showing a google map Google Maps API:同一地图上的多个方向/路线 - Google Maps API : multiple direction/route on same map 使用CodeIgniter Google Maps API后以Javascript获取地图对象 - Get Map Object in Javascript after using CodeIgniter Google Maps API Google Maps API V3:如何使用从A点到B点的方向获取多个路径距离 - Google Maps API V3 : How to get multiple path distances using direction from a point A to point B 获取以公里为单位的Google Maps API地图的宽度 - Get width in kilometers of Google Maps API map Google Map-使用API​​获取在该特定路线上放置和查找路况的路线 - Google Map - get direction to place and find traffic on that particular route using API 使用node-googlemaps从谷歌地图获取方向 - Using node-googlemaps to get direction from google maps 使用Google Maps API时地图不显示 - Map not showing when using Google Maps API 谷歌地图:在没有 API 的情况下向嵌入的谷歌地图添加标记 - Google Maps: Add a marker to the embedded Google map without their API Google Maps API - 如何在不显示地图的情况下从自动完成获取纬度和经度? - Google Maps API - how to get latitude and longitude from Autocomplete without showing the map?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM