Repository navigation
[geo-tools] GoogleAddressProvider now handles more API variants for location requests - #1719
Conversation
|
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. |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
b7a8e75 to
32ec7f5
Compare
…r-does-not-resolve-location-request-correctly
…r-does-not-resolve-location-request-correctly
|
@mdastous-bentley Hi, could we get a review on this PR? These changes were already approved in https://github.com/iTwin/itwinjs-internal/pull/561 and are duplicated here. |
There was a problem hiding this comment.
🟢 Approval recommended
The localized changes preserve legacy support and include focused regression coverage, with no identified blocking issues; tests were not executed.
No open issues 🎉
What changed in this PR
Extends GoogleAddressProvider to resolve coordinates from additional response formats while retaining legacy support.
Changes:
- Adds coordinate fallbacks and finite-number validation.
- Adds regression tests for supported formats, zero coordinates, and invalid data.
- Includes a patch release changeset.
| File | Description |
|---|---|
packages/geo-tools/src/test/GoogleAddressProvider.test.ts |
Tests response formats and coordinate validation. |
packages/geo-tools/src/GoogleAddressProvider.ts |
Expands coordinate extraction and validation. |
.changeset/@itwin-geo-tools-react-location-response-variants.md |
Documents the package patch release. |
Review effort: Balanced
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.