Google Geocoding — parsing address_components that may return differently

前端 未结 2 807
庸人自扰
庸人自扰 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.

    0 讨论(0)
  • 2021-02-06 01:28

    Addresses are very much a 'human' thing. I think the reason Google's data is so messy is because their source data is messy, but likely similar for one area.

    Which parts of the address are relevant to you? If you're just feeding this to a human just give him whatever you have?

    0 讨论(0)
提交回复
热议问题