如何获取完整address_component值列表及小众地址元素可选值?
address_component Values for Google Places API Great question—this is a common pain point since the official Places Details docs only show examples of the address_component array instead of a complete list of possible values. Here’s how you can track down all possible types, including niche elements like pre-directions and post-directions:
1. Use the Shared Type System with Geocoding API
The Google Places API shares the exact same address_component type framework as the Geocoding API, which has a more comprehensive documented list of types. This includes under-documented options like:
subpremise: For apartment numbers, unit IDs, or suite numbersneighborhood: Localized community or neighborhood namespostal_code_suffix: The secondary part of a postal code (e.g., the "1234" in "90210-1234")administrative_area_level_4/administrative_area_level_5: Hyper-local administrative divisions used in some countries
2. Test Diverse Addresses to Capture Niche Types
The most reliable way to uncover rare or region-specific types is to send Places Details requests for addresses that include the elements you care about. For example:
- Pre/post-directions: Test addresses like "123 North Main Street" or "456 Oak Avenue West"—you’ll find direction prefixes/suffixes either embedded in the
routecomponent’s name, or in some regions, as a standalone component tied to street orientation. - Special address formats: Test PO boxes ("PO Box 789"), military addresses, or European-style addresses with plazas to capture types like
premiseorintersection. - International addresses: Check addresses from countries with unique structures (e.g., Japan’s chōme-block system, India’s village-level divisions) to find region-exclusive types.
3. Tap Into Community-Curated Lists
Many developers have shared compiled lists of address_component types on platforms like Stack Overflow. These often include niche types that don’t make it into official docs, such as:
postal_town: Used in the UK to denote the main town linked to a postal codesublocality_level_3/sublocality_level_4: Ultra-local neighborhood divisionsstreet_number_prefix: Rarely used, but appears in some regions for numbered street prefixes
4. Parse for Directional Elements
For pre-direction and post-direction specifically, since they’re often not standalone components, you can:
- Split the
routecomponent’slong_nameorshort_nameto extract directional terms (e.g., "North", "W", "West") using regex or string matching tailored to regional address conventions. - Check for components where the
typesarray includesrouteand the name is a directional term—this occurs in some regions where directions are treated as separate address elements.
Remember, address structures vary wildly by country, so always build fallback logic to handle cases where a niche element isn’t returned.
内容的提问来源于stack exchange,提问作者Dave Graham

