gpt4 book ai didi

android - 谷歌地图 API : How to manage different "address_components" in gecoding results?

转载 作者:行者123 更新时间:2023-11-29 15:36:56 24 4
gpt4 key购买 nike

考虑以下 google map 地理编码响应的 JSON 响应。它由一组 address_components 组成有五个元素。通常开发人员使用它的第一个项目(索引为 0 的项目)来查找地址元素,例如 ac routelocalityformatted address .但这不是最好的选择。例如,在这种情况下,第二项是比其他项更具描述性的地址。有时在同一个响应中会有不同地区的相同地址。

我如何选择更好的(例如,Android 中的 Google Map API 从可用项目中选择一个,但它并不总是索引为 0 的项目,但它会在备选方案中进行选择,我想知道它将如何做到这一点并选择最佳匹配)?

此外,我想遍历不同 address_components 的所有元素提取和汇集更精细的信息,但问题是相同类型元素的信息,如 locality在不同的地方有不同的信息address_components当信息元素从不同的 address_component 收集时,会导致地址不一致项目。例如,在下面的示例中,我们有两个值 شهر جدید اندیشهKaraj在不同locality元素是两个不同的城市标签(在同一街区)。

https://maps.googleapis.com/maps/api/geocode/json?latlng=35.7163931455472,51.01335000246763&key=xxxxx&language=fa

{
"results" : [
{
"address_components" : [
{
"long_name" : "Unnamed Road",
"short_name" : "Unnamed Road",
"types" : [ "route" ]
},
{
"long_name" : "Karaj",
"short_name" : "Karaj",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Shahriar County",
"short_name" : "Shahriar County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Tehran Province",
"short_name" : "Tehran Province",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "ایران",
"short_name" : "IR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Tehran Province, Karaj, Unnamed Road, ایران",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.7221382,
"lng" : 51.0148178
},
"southwest" : {
"lat" : 35.716435,
"lng" : 51.0095103
}
},
"location" : {
"lat" : 35.719286,
"lng" : 51.012165
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 35.7221382,
"lng" : 51.0148178
},
"southwest" : {
"lat" : 35.716435,
"lng" : 51.0095103
}
}
},
"place_id" : "ChIJmf7_zEyTjT8RkM8-nK6dTm0",
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "فاز ۶ شهر جدید اندیشه",
"short_name" : "فاز ۶ شهر جدید اندیشه",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "شهر جدید اندیشه",
"short_name" : "شهر جدید اندیشه",
"types" : [ "locality", "political" ]
},
{
"long_name" : "شهرستان شهریار",
"short_name" : "شهرستان شهریار",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "استان تهران",
"short_name" : "استان تهران",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "ایران",
"short_name" : "IR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "فاز ۶ شهر جدید اندیشه، شهر جدید اندیشه، استان تهران، ایران",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.7389537,
"lng" : 51.0349971
},
"southwest" : {
"lat" : 35.7039031,
"lng" : 51.0044146
}
},
"location" : {
"lat" : 35.7210753,
"lng" : 51.014934
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.7389537,
"lng" : 51.0349971
},
"southwest" : {
"lat" : 35.7039031,
"lng" : 51.0044146
}
}
},
"place_id" : "ChIJiYlwJLHsjT8RruE39U9NMoQ",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"address_components" : [
{
"long_name" : "شهر جدید اندیشه",
"short_name" : "شهر جدید اندیشه",
"types" : [ "locality", "political" ]
},
{
"long_name" : "شهرستان شهریار",
"short_name" : "شهرستان شهریار",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "استان تهران",
"short_name" : "استان تهران",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "ایران",
"short_name" : "IR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "شهر جدید اندیشه، استان تهران، ایران",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.7388144,
"lng" : 51.04460479999999
},
"southwest" : {
"lat" : 35.6838973,
"lng" : 50.9894371
}
},
"location" : {
"lat" : 35.7078282,
"lng" : 51.0227587
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.7388144,
"lng" : 51.04460479999999
},
"southwest" : {
"lat" : 35.6838973,
"lng" : 50.9894371
}
}
},
"place_id" : "ChIJIQwwRcnsjT8RnTJfLJ3QUAg",
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "شهرستان شهریار",
"short_name" : "شهرستان شهریار",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "استان تهران",
"short_name" : "استان تهران",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "ایران",
"short_name" : "IR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "شهرستان شهریار، استان تهران، ایران",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.7389885,
"lng" : 51.23044970000001
},
"southwest" : {
"lat" : 35.5333437,
"lng" : 50.8859253
}
},
"location" : {
"lat" : 35.6096201,
"lng" : 51.03319330000001
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.7389885,
"lng" : 51.23044970000001
},
"southwest" : {
"lat" : 35.5333437,
"lng" : 50.8859253
}
}
},
"place_id" : "ChIJQ6KQjY7xjT8RoYD9gJh8_CY",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "استان تهران",
"short_name" : "استان تهران",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "ایران",
"short_name" : "IR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "استان تهران، ایران",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 36.07789210000001,
"lng" : 53.216228
},
"southwest" : {
"lat" : 34.909543,
"lng" : 50.3186971
}
},
"location" : {
"lat" : 35.7248416,
"lng" : 51.381653
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 36.07789210000001,
"lng" : 53.216228
},
"southwest" : {
"lat" : 34.909543,
"lng" : 50.3186971
}
}
},
"place_id" : "ChIJf5Us9YQBjj8R0OohvHQms1U",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "ایران",
"short_name" : "IR",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "ایران",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 39.782056,
"lng" : 63.3333366
},
"southwest" : {
"lat" : 24.8066999,
"lng" : 44.0326949
}
},
"location" : {
"lat" : 32.427908,
"lng" : 53.688046
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 39.782056,
"lng" : 63.3333366
},
"southwest" : {
"lat" : 24.8066999,
"lng" : 44.0326949
}
}
},
"place_id" : "ChIJ8R1rwS7s9z4RzvpRntOVsEA",
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}

最佳答案

一个问题好像是两个不同的问题,所以范围有点宽泛。我会尽力解决您的疑虑。

首先,您使用反向地理编码请求将坐标 35.7163931455472,51.01335000246763 解析为街道地址。注意 reverse geocoding旨在将给定坐标解析为最近的可用地址。除了街道地址之外,该服务还将建议不同类型的结果:路线、次地区、地区、行政区域、国家/地区。有时,如果给定点附近没有街道地址(距离该点约 50 米以内),则街道地址类型的结果不会出现在响应中。在您的示例中,街道地址类型的结果不可用,因此响应包含从路线级别开始的不同类型的结果。请查看我的屏幕截图,其中显示了您回复中的前三项。

enter image description here

如您所见,第一项具有类型路线,第二项具有类型子区域,第三项具有类型区域。

很难说选择地址的“最佳”标准是什么。你可以看到路线项是最近的,但不幸的是这条路没有命名,所以你把它定性为不够好。从技术上讲,这是最接近的项目,因此服务假定这是最佳匹配。我会建议检查结果的类型,如果项目 0 有一个类型 street_address 应该足够好,如果项目 0 有一个类型 route,检查道路是否有名字,如果这是未命名的道路检查项目1 可能更详细。

无论如何,未命名的道路是数据问题,您可以按照帮助中心将其报告给 Google 数据团队:

https://support.google.com/maps/answer/3094088

其次,如果我理解正确的话,您注意到项目 0 和项目 1 具有不同的位置地址组件值,尽管它们(我的屏幕截图中的标记 1 和标记 2)似乎都属于 Andisheh 新城。该路线(地点 ID ChIJmf7_zEyTjT8RkM8-nK6dTm0)被报告为 Karaj 地区的一部分。我可以在 Google map 上看到 Karaj 的边界,如下图所示

enter image description here

https://www.google.com/maps/place/Karaj,+Alborz+Province,+Iran/@35.7700272,50.95899,12.41z/data=!4m5!3m4!1s0x3f8dbf95ef45f011:0x722a04e54eba9bcd!8m2!3d35.8400188!4d50.9390906

我可以看到安迪舍新城的边界,如下图所示

enter image description here

https://www.google.com/maps/place/Andisheh+New+Town,+Tehran+Province,+Iran/@35.6998795,51.0216598,14.08z/data=!4m5!3m4!1s0x3f8decc945300c21:0x850d09d2c5f329d!8m2!3d35.7078282!4d51.0227587

请注意,您回复的路线显然位于 Andisheh New Town 多边形内,因此目前看来我们也面临着数据问题。地点 ID ChIJmf7_zEyTjT8RkM8-nK6dTm0 应该包含安迪舍新城的地点成分,而不是卡拉季。

请随时使用此页面向 Google 发送反馈:

https://www.google.com/maps/place/Tehran+Province,+Karaj,+Unnamed+Road,+Iran/@35.719286,51.0077876,17z/data=!3m1!4b1!4m5!3m4!1s0x3f8d934cccfffe99:0x6d4e9dae9c3ecf90!8m2!3d35.719286!4d51.012165!10m2!1e3!2e3

如果您想玩反向地理编码,请使用 Geocoder 工具:

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D35.716393%252C51.01335

希望我的回答能解开你的疑惑!

关于android - 谷歌地图 API : How to manage different "address_components" in gecoding results?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47869296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com