我正在开发一个使用谷歌进行地理编码和计算旅行时间的项目,它主要工作正常,但我看到一些莫名其妙的行为与下列情况。
使用谷歌地图,我可以正确地看到两个位置之间的路线为3.6英里,但是当我使用谷歌距离矩阵进行相同的路线时,api会返回151英里。
(来自网址的googlemaps api密钥)
1)对邮政编码LN68SD进行地理编码
https://maps.googleapis.com/maps/api/geocode/json?address=LN68SD&key=MapsAPIKey®ion=uk
地理编码正确返回位置53.2017314,-0.5642401(林肯,英国)
2)对邮政编码LN57FB进行地理编码
https://maps.googleapis.com/maps/api/geocode/json?address=LN57FB&key=MapsAPIKey®ion=uk
地理编码正确返回位置53.2265083,-0.5246126(林肯,英国)
3)显示两个地点之间的路线:
https://www.google.co.uk/maps/dir/53.2017314,+-0.5642401/53.226509094238281,+-0.52461260557174683
地图正确返回3.6英里,15分钟
4)获取两个位置之间的距离矩阵:
distancematrix错误地指出位置相距150英里(林肯/伦敦)
// 20170523131103
// https://maps.googleapis.com/maps/api/distancematrix/json?&origins=53.2017314,-0.5642401&destinations=53.2265090942383,-0.524612605571747,UK&key=MapsAPIKey®ion=uk&mode=driving&units=imperial
{
"destination_addresses": [
"99-101 Newington Causeway, London SE1 6BN, UK"
],
"origin_addresses": [
"1 Chancery Cl, Lincoln LN6, UK"
],
"rows": [
{
"elements": [
{
"distance": {
"text": "151 mi",
"value": 243015
},
"duration": {
"text": "2 hours 53 mins",
"value": 10354
},
"status": "OK"
}
]
}
],
"status": "OK"
}
答案 0 :(得分:2)
您对距离矩阵(目的地中的“,UK”)的请求中有拼写错误。如果我确定我get the expected result(“3.6 mi”)
https://maps.googleapis.com/maps/api/distancematrix/json?&origins=53.2017314,-0.5642401&destinations=53.2265090942383,-0.524612605571747®ion=uk&mode=driving&units=imperial
{
"destination_addresses" : [ "Waterside S, Lincoln LN5 7FB, UK" ],
"origin_addresses" : [ "1 Chancery Cl, Lincoln LN6, UK" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "3.6 mi",
"value" : 5864
},
"duration" : {
"text" : "15 mins",
"value" : 889
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}