From 569fa26a13fba0c28de77c4bee92c5d85b8668d3 Mon Sep 17 00:00:00 2001 From: Xavi Bonell Date: Wed, 26 Feb 2020 11:52:17 +0100 Subject: [PATCH] fix(geosuggest): changing default API call to the geocoder interface --- src/Geosuggest.tsx | 67 +++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/src/Geosuggest.tsx b/src/Geosuggest.tsx index 7b320039..11617bba 100644 --- a/src/Geosuggest.tsx +++ b/src/Geosuggest.tsx @@ -485,53 +485,30 @@ export default class extends React.Component { if (!this.geocoder) { return; } + + const options: google.maps.GeocoderRequest = { + address: suggestToGeocode.label, + bounds: this.props.bounds, + componentRestrictions: this.props.country + ? {country: this.props.country} + : undefined, + location: this.props.location + }; - if (suggestToGeocode.placeId && !suggestToGeocode.isFixture && this.placesService) { - const options = { - placeId: suggestToGeocode.placeId, - sessionToken: this.sessionToken - }; - - this.placesService.getDetails(options, (results, status) => { - if (status === this.googleMaps.places.PlacesServiceStatus.OK) { - const gmaps = results; - const location = gmaps.geometry.location; - const suggest = {...suggestToGeocode, gmaps, location: { - lat: location.lat(), - lng: location.lng() - }}; - - this.sessionToken = new google.maps.places.AutocompleteSessionToken(); - if (this.props.onSuggestSelect) { - this.props.onSuggestSelect(suggest); - } - } - }); - } else { - const options: google.maps.GeocoderRequest = { - address: suggestToGeocode.label, - bounds: this.props.bounds, - componentRestrictions: this.props.country - ? {country: this.props.country} - : undefined, - location: this.props.location - }; - - this.geocoder.geocode(options, (results, status) => { - if (status === this.googleMaps.GeocoderStatus.OK) { - const gmaps = results[0]; - const location = gmaps.geometry.location; - const suggest = {...suggestToGeocode, gmaps, location: { - lat: location.lat(), - lng: location.lng() - }}; - - if (this.props.onSuggestSelect) { - this.props.onSuggestSelect(suggest); - } + this.geocoder.geocode(options, (results, status) => { + if (status === this.googleMaps.GeocoderStatus.OK) { + const gmaps = results[0]; + const location = gmaps.geometry.location; + const suggest = {...suggestToGeocode, gmaps, location: { + lat: location.lat(), + lng: location.lng() + }}; + + if (this.props.onSuggestSelect) { + this.props.onSuggestSelect(suggest); } - }); - } + } + }); } /**