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 689dfd9 commit 7e3f714
Showing 1 changed file with 24 additions and 58 deletions.
82 changes: 24 additions & 58 deletions src/Geosuggest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -501,68 +501,34 @@ export default class extends React.Component<IProps, IState> {
return;
}

if (
suggestToGeocode.placeId &&
!suggestToGeocode.isFixture &&
this.placesService
) {
const options: any = {
placeId: suggestToGeocode.placeId,
sessionToken: this.sessionToken
};

if (this.props.placeDetailFields) {
options.fields = ['geometry', ...this.props.placeDetailFields];
}

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()
}
};
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.sessionToken = new google.maps.places.AutocompleteSessionToken();
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()
}
}
});
} 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);
}
if (this.props.onSuggestSelect) {
this.props.onSuggestSelect(suggest);
}
});
}
}
});

}

/**
Expand Down

0 comments on commit 7e3f714

Please sign in to comment.