[geo-tools] GoogleAddressProvider now handles more API variants for location requests#1719
Open
johannes-goltz wants to merge 2 commits into
Conversation
Contributor
|
The fix looks correct, but the inline comment could be more descriptive for future maintainers. Consider mapping each fallback arm to the specific API that produces that response shape: // Google Address Validation API response shape: { location: { latitude, longitude } }
// @see https://developers.google.com/maps/documentation/address-validation/reference/rest/v1/TopLevel/validateAddress#Location
const lat = json?.location?.latitude
// Google Geocoding API response shape: { result: { geometry: { location: { lat, lng } } } }
// @see https://developers.google.com/maps/documentation/geocoding/requests-geocoding#Results
?? json?.result?.geometry?.location?.lat
// Legacy/wrapper format: { location: { geometry: { latitude, longitude } } }
?? json?.location?.geometry?.latitude;
const long = json?.location?.longitude
?? json?.result?.geometry?.location?.lng
?? json?.location?.geometry?.longitude;This makes it clear which Google API produces each shape, so anyone encountering a new variant in the future knows exactly where to add the next fallback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
The GoogleAddressProvider does not always resolve a given place ID to coordinates correctly. It seems the API
supports different variants of query responses but only one variant (legacy ???) is currently accpted.
see screen shoot from my debug session:

Solution
GoogleAddressProvider.ts: broadened location extraction to accept alternative response shapes (top-level location, nested result.geometry.location.lat/lng, and other geometry variants). Kept existing behavior while adding fallbacks and validation.