Skip to content

Commit

Permalink
fix(geosuggest): changing default API call to the geocoder interface
Browse files Browse the repository at this point in the history
  • Loading branch information
xavibonell-badi committed Feb 26, 2020
1 parent 5f5e028 commit 569fa26
Showing 1 changed file with 22 additions and 45 deletions.
67 changes: 22 additions & 45 deletions src/Geosuggest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -485,53 +485,30 @@ export default class extends React.Component<IProps, IState> {
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);
}
});
}
}
});
}

/**
Expand Down

0 comments on commit 569fa26

Please sign in to comment.