我正在尝试使用google geocode api从给定的位置字符串中提取lat / lng坐标。但是,返回的JSON结果不一致,我不确定原因:
结果
{
"results" : [
{
"address_components" : [
{
"long_name" : "Mit Nagy",
"short_name" : "Mit Nagy",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Mit Nagy",
"short_name" : "Mit Nagy",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Mit Ghamr",
"short_name" : "Mit Ghamr",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Daqahlia",
"short_name" : "Daqahlia",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Egypt",
"short_name" : "EG",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Mit Nagy, Mit Ghamr, Daqahlia, Egypt",
"geometry" : {
"location" : {
"lat" : 30.6705522,
"lng" : 31.2912754
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 30.6801489,
"lng" : 31.3072828
},
"southwest" : {
"lat" : 30.6609546,
"lng" : 31.275268
}
}
},
"partial_match" : true,
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
请注意,获取该位置的层次结构为response->results[0]->geometry->location
结果
{
"results" : [
{
"address_components" : [
{
"long_name" : "Markaz Itay Al Baroud",
"short_name" : "Markaz Itay Al Baroud",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Beheira",
"short_name" : "Beheira",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Egypt",
"short_name" : "EG",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Markaz Itay Al Baroud, Beheira, Egypt",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 30.9757371,
"lng" : 30.7938058
},
"southwest" : {
"lat" : 30.7921464,
"lng" : 30.5296768
}
},
"location" : {
"lat" : 30.8891275,
"lng" : 30.6660044
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 30.9757371,
"lng" : 30.7938058
},
"southwest" : {
"lat" : 30.7921464,
"lng" : 30.5296768
}
}
},
"partial_match" : true,
"types" : [ "administrative_area_level_2", "political" ]
}
],
"status" : "OK"
}
在这种情况下,位置不再位于 geometry 键下:
response->results[0]->location
API documentation中的示例显示该位置始终位于几何键下,那么为什么它会将其返回一级呢?
答案 0 :(得分:1)
对于您为什么看到这些不一致的问题没有答案,但请考虑HERE Geocoder以获得一致的结果。
API文档位于developer.here.com/geocoder 每日免费限额为2,500笔交易。
请参阅以下位置的两个示例查询:
Mit Nagy
Markaz Itay Al Baroud
完全披露:我是HERE Geocoder的产品经理。