Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "GoogleAddressProvider does not always resolve location requests correctly. Now handling different API variants",
"packageName": "@itwin/geo-tools-react",
"email": "Johannes.Goltz@bentley.com",
"dependentChangeType": "patch"
}
15 changes: 13 additions & 2 deletions packages/itwin/geo-tools/src/GoogleAddressProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,19 @@ export class GoogleAddressProvider implements AddressProvider {
} });
const json: any = await response.json();

const lat = json?.location?.geometry?.latitude
const long = json?.location?.geometry?.longitude
// 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;

if (lat === undefined || long === undefined) {
throw new Error("Invalid location data");
}
Expand Down
Loading