使用lat / long的源和目的地通过Python中的Google Directions API获取路线

问题描述 投票:3回答:2

考虑到A和B的纬度/经度坐标,我只想使用Google Directions API来获取从A点到B点的路线/方向。我想在Python中执行此操作。

如果我这样做,它的工作原理:

import googlemaps
gmaps = googlemaps.Client(key='mykey')
start = 'Constitution Ave NW & 10th St NW, Washington, DC'
end   = 'Independence and 6th SW, Washington, DC 20024, USA'
dirs  = gmaps.directions(start, end)

然而,这不是我想要的,因为我只有纬度/经度坐标,而不是地址。我知道我可以使用reverse_geocode()将lat / long转换为地址,但这不是我想要的,因为它会在Directions API之上调用Geocoding API。我还没有找到一种方法直接在lat / long上使用gmaps.directions()。

所以我的问题很简单:当我只有A和B的纬度/经度坐标时,我可以单独使用Directions API来获得从A点到B点的方向吗?或者我是否有义务在其上使用Geocoding API?

感谢您的时间。

google-maps-api-3 google-api google-geocoding-api google-direction
2个回答
2
投票

根据谷歌的the Developer's Guide的说法:

如果传递坐标,则不加改变地使用它们来计算方向。确保纬度和经度值之间不存在空格。 origin=41.43206,-81.38992


0
投票

请使用以下方式给出纬度和经度。希望它会有所帮助:

origin: {lat:19.99, lng:73.78},  // Start Point
destination: {lat:19.697316, lng:73.560936},  // End Point
© www.soinside.com 2019 - 2024. All rights reserved.