javascript 如何将起点和终点坐标传递给 Google Maps 路线 API?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7538861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I pass origin and destination co-ordinates to the Google Maps directions API?
提问by andrei
I'm using the google maps api for directions but i'm having problems when i try to send the origin and destination as coordinates.it says in the documentation that i can do that
我正在使用 google maps api 获取方向,但是当我尝试将起点和终点作为坐标发送时遇到问题。它在文档中说我可以这样做
http://code.google.com/apis/maps/documentation/directions/#RequestParameters
http://code.google.com/apis/maps/documentation/directions/#RequestParameters
but i am not sure of the format because it keeps giving me errors
但我不确定格式,因为它不断给我错误
Uncaught Error: Invalid value for property <origin>: [object Object]
i tried like so:
我试过这样:
{"Ja":27,"Ka":45}
{latitude:27,longitude:45}
And all of the possible combinations above but still gives error which is weird because the objects are identical with the ones i should be sending.
上面所有可能的组合,但仍然给出错误,这很奇怪,因为对象与我应该发送的对象相同。
回答by Dr.Molle
Just provide the latidute/longitude separated by a comma as textual value:
只需提供以逗号分隔的纬度/经度作为文本值:
http://maps.google.com/maps/api/directions/json?origin=27.111,45.222&destination=28.333,46.444&sensor=false
http://maps.google.com/maps/api/directions/json?origin=27.111,45.222&destination=28.333,46.444&sensor=false
回答by Peter Mwenda
Use Google distancematrix API:
使用谷歌距离矩阵 API:
https://maps.googleapis.com/maps/api/distancematrix/json?origins=-0.6566588,35.0881299&destinations=-0.6433411,35.094122&mode=driving