Google Geocoding — parsing address_components that may return differently

前端 未结 2 812
庸人自扰
庸人自扰 2021-02-06 00:53

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 prob

2条回答
  •  时光取名叫无心
    2021-02-06 01:14

    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 - http://code.google.com/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.

提交回复
热议问题