Google地理编码

编程入门 行业动态 更新时间:2024-10-28 06:32:25
本文介绍了Google地理编码 - 解析可能返回不同的地址组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Google Maps V3 api。我正在提交地址搜索以返回地理编码结果,包括地址,企业名称和纬度/经度。

我的问题是来自地理编码器的响应可以格式不同。它总是遵循相同的结构,但是一些响应对address_components数据结构使用不同的键。

例如,一些搜索结果为:

建立 - >位置名称 street_number - >地址街道号码路线 - >街道名称 locality - >城市 administrative_area_level_1 - >州 postal_code - >邮政编码

然而,如果我要搜索一个普通区域,例如Hampton Beach NH我会收到:

sublocality - >海滩名称/地区 administrative_area_level_3 - >城市/城镇名称 administrative_area_level_1 - >州 postal_code - >邮政编码

您可以看到这两个回复有不同之处。是否有一个已知的jQuery库可用于处理这些不同的响应,以返回可用于人类可读方式的地址组件的数据集?

我会注意到,响应还会返回一个formatted_address类型,它返回如下形式:Hampton Beach,NH 03842,USA或Boston University,1 University Rd,Boston,MA 02215-1407,USA如您所见这些也非常不同。我可以用逗号分割,但是我想用实际的address_components来完成一个完美的数据库插入。

解决方案

你的数据库镜像只有下列键?

street_number - >地址街道号码路线 - >街道名称 locality - >城市/城镇 administrative_area_level_3 - >城市/城镇 administrative_area_level_1 - >州 postal_code - >邮政编码

存在地点存在,请在您的请求中使用它(因为它似乎提供了更详细的信息 - http ://code.google/apis/maps/documentation/geocoding/#JSON )

凡没有街道名称或 locality 存在,请求 administrative_area_level_3 和 administrative_area_level_1 这将为您提供一个完整的人类可读的邮政地址,当信息存在或只是一个子地点(例如海滩)的城市/州时,您在一个评论中提到。

**我假设你只关心美国。

I'm using Google Maps V3 api. I am submitting an address search to return the proper geocoded result including the address, name of establishment, and lat/lngs.

My problem is that the response from the geocoder can be formatted differently. It always follows the same structure, but some responses use different keys for the address_components data structure.

For Example, some searches result in:

establishment -> location name street_number -> address street number route -> the street name locality -> the city administrative_area_level_1 -> the state postal_code -> zip/postal code

whereas, if i were to search a general area, such as "Hampton Beach, NH" i would receive:

sublocality -> beach name / area administrative_area_level_3 -> city/town name administrative_area_level_1 -> the state postal_code -> zip/postal code

as you can see the two responses have their differences. Is there a known jquery library that can be used to handle these different responses to return a data set of the address components that can be used for a human-readable way?

I will note that the response also returns a "formatted_address" type, which returns it like: "Hampton Beach, NH 03842, USA" OR "Boston University, 1 University Rd, Boston, MA 02215-1407, USA" As you can see, these too are pretty different. I could split by comma, but I'd like to use the actual address_components for a flawless database insert.

解决方案

Why not have your DB mirror only the following keys?

street_number -> address street number route -> the street name locality -> the city/town administrative_area_level_3 -> the city/town administrative_area_level_1 -> the state postal_code -> zip/postal code

Where a locality exists, use that in your request (as it appears to deliver the more detailed info - code.google/apis/maps/documentation/geocoding/#JSON )

Where no street name or locality exists, request administrative_area_level_3 and administrative_area_level_1

This would provide you with a full human-readable postal address when the info exists or just the city/state for a sublocality (e.g. beach), as you mentioned in one of the comments.

**I'm assuming you only care about the US.

更多推荐

Google地理编码

本文发布于:2023-05-29 21:35:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/353356.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地理   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!