Skip to content

[geo-tools] GoogleAddressProvider now handles more API variants for location requests - #1719

Merged
aruniverse merged 5 commits into
masterfrom
JohannesG/-geo-tools]-GoogleAddressProvider-does-not-resolve-location-request-correctly
Oct 20, 2026
Merged

aruniverse merged 5 commits into
masterfrom
JohannesG/-geo-tools]-GoogleAddressProvider-does-not-resolve-location-request-correctly

Conversation

@johannes-goltz

@johannes-goltz johannes-goltz commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

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:
image

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.

@johannes-goltz
johannes-goltz requested review from a team and mdastous-bentley as code owners June 15, 2026 08:54
@CLAassistant

CLAassistant commented Jun 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jason-crow

jason-crow commented Jun 15, 2026 •

Copy link
Copy Markdown
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.

@mjkertz
mjkertz force-pushed the JohannesG/-geo-tools]-GoogleAddressProvider-does-not-resolve-location-request-correctly branch from b7a8e75 to 32ec7f5 Compare September 21, 2026 20:19
…r-does-not-resolve-location-request-correctly
…r-does-not-resolve-location-request-correctly
@mjkertz

mjkertz commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

@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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@aruniverse
aruniverse merged commit d67899d into master Oct 20, 2026
13 checks passed
@aruniverse
aruniverse deleted the JohannesG/-geo-tools]-GoogleAddressProvider-does-not-resolve-location-request-correctly branch October 20, 2026 16:39
@imodeljs-admin imodeljs-admin mentioned this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants