简体   繁体   English

使用Google Maps API查找两个位置之间的路线和距离,并将其显示在表格中

[英]Using Google Maps API to find routes & distance between two locations and present it in a table

I want to use Google maps to find out available routes between two cities. 我想使用谷歌地图找出两个城市之间的可用路线。 Some information about these routes like distance and travel time etc. 有关这些路线的一些信息,如距离和旅行时间等。

I do not want this data to be presented in a Map. 希望这些数据显示在地图中。 I need this to be presented to end user in textual format. 我需要以文本格式呈现给最终用户。

User will give me two cities and I will present him with various routes and information in a table. 用户将给我两个城市,我将在表格中向他呈现各种路线和信息。

Can this be done using PHP, MySQL and Google Maps? 可以使用PHP,MySQL和Google Maps完成吗? Any pointers would be very helpful. 任何指针都会非常有用。

If you want multiple routes between two points, use the directions service (http://code.google.com/apis/maps/documentation/directions) and specify alternatives=true in the request. 如果您需要两个点之间的多条路线,请使用路线服务(http://code.google.com/apis/maps/documentation/directions)并在请求中指定alternatives=true This will return alternate routes, if they're available. 如果它们可用,这将返回备用路线。 Then, parse the response for the desired information: 然后,解析所需信息的响应:

  • there will be one legs array for each route 每条路线都会有一个legs
  • within that legs array, there is a distance and a duration field, each containing a raw value and a textual value. 在该legs数组中,有一个distance和一个duration字段,每个字段包含一个原始值和一个文本值。

If you don't need multiple choices for the route, the Google Maps Distance Matrix service (http://code.google.com/apis/maps/documentation/distancematrix/) provides travel distance and time between multiple origins and destinations, without all of the directions information. 如果您不需要多个路线选择,Google地图距离矩阵服务(http://code.google.com/apis/maps/documentation/distancematrix/)会提供多个来源和目的地之间的行程距离和时间,所有方向信息。

A sample table is in the blog post: http://googlegeodevelopers.blogspot.com/2011/05/what-is-distance-matrix.html 博客文章中有一个示例表: http//googlegeodevelopers.blogspot.com/2011/05/what-is-distance-matrix.html

Google Maps Direction Service can give you textual information. Google地图指导服务可以为您提供文字信息。 See the documentation here: http://code.google.com/apis/maps/documentation/javascript/services.html#Directions Particularly the bit starting "A DirectionsRenderer not only handles display of the polyline and any associated markers, but also can handle the textual display of directions as a series of steps. To do so, simply call setPanel() on your DirectionsRenderer, passing it the in which to display this information." 请参阅此处的文档: http//code.google.com/apis/maps/documentation/javascript/services.html#Directions特别是开头的位置“A DirectionsRenderer不仅可以处理折线和任何相关标记的显示,还可以处理方向的文本显示作为一系列步骤。为此,只需在DirectionsRenderer上调用setPanel(),并在其中传递显示此信息的内容。“

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM