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
2 changes: 1 addition & 1 deletion example/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title>React Geosuggest</title>
<link href='http://fonts.googleapis.com/css?family=Roboto:300,100,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="app.css">
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyBG0SybP0EKWH3Jvwki7IR5AMyO_cUeeQc"></script>
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyAF8FxJ14ikiajwnNH2VsV15lqSdT2PBK0"></script>
</head>
<body>
<div class="container">
Expand Down
67 changes: 20 additions & 47 deletions module/Geosuggest.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1481,54 +1481,27 @@ var default_1$3 = /** @class */ (function (_super) {
if (!this.geocoder) {
return;
}
if (suggestToGeocode.placeId &&
!suggestToGeocode.isFixture &&
this.placesService) {
var options = {
placeId: suggestToGeocode.placeId,
sessionToken: this.sessionToken
};
if (this.props.placeDetailFields) {
options.fields = ['geometry'].concat(this.props.placeDetailFields);
}
this.placesService.getDetails(options, function (results, status) {
if (status === _this.googleMaps.places.PlacesServiceStatus.OK) {
var gmaps = results;
var location_1 = gmaps.geometry.location;
var suggest = __assign({}, suggestToGeocode, { gmaps: gmaps, location: {
lat: location_1.lat(),
lng: location_1.lng()
} });
_this.sessionToken = new google.maps.places.AutocompleteSessionToken();
if (_this.props.onSuggestSelect) {
_this.props.onSuggestSelect(suggest);
}
}
});
}
else {
var options = {
address: suggestToGeocode.label,
bounds: this.props.bounds,
componentRestrictions: this.props.country
? { country: this.props.country }
: undefined,
location: this.props.location
};
this.geocoder.geocode(options, function (results, status) {
if (status === _this.googleMaps.GeocoderStatus.OK) {
var gmaps = results[0];
var location_2 = gmaps.geometry.location;
var suggest = __assign({}, suggestToGeocode, { gmaps: gmaps, location: {
lat: location_2.lat(),
lng: location_2.lng()
} });
if (_this.props.onSuggestSelect) {
_this.props.onSuggestSelect(suggest);
}
var options = {
address: suggestToGeocode.label,
bounds: this.props.bounds,
componentRestrictions: this.props.country
? { country: this.props.country }
: undefined,
location: this.props.location
};
this.geocoder.geocode(options, function (results, status) {
if (status === _this.googleMaps.GeocoderStatus.OK) {
var gmaps = results[0];
var location_1 = gmaps.geometry.location;
var suggest = __assign({}, suggestToGeocode, { gmaps: gmaps, location: {
lat: location_1.lat(),
lng: location_1.lng()
} });
if (_this.props.onSuggestSelect) {
_this.props.onSuggestSelect(suggest);
}
});
}
}
});
};
/**
* Render the view
Expand Down
67 changes: 20 additions & 47 deletions module/Geosuggest.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,54 +1487,27 @@
if (!this.geocoder) {
return;
}
if (suggestToGeocode.placeId &&
!suggestToGeocode.isFixture &&
this.placesService) {
var options = {
placeId: suggestToGeocode.placeId,
sessionToken: this.sessionToken
};
if (this.props.placeDetailFields) {
options.fields = ['geometry'].concat(this.props.placeDetailFields);
}
this.placesService.getDetails(options, function (results, status) {
if (status === _this.googleMaps.places.PlacesServiceStatus.OK) {
var gmaps = results;
var location_1 = gmaps.geometry.location;
var suggest = __assign({}, suggestToGeocode, { gmaps: gmaps, location: {
lat: location_1.lat(),
lng: location_1.lng()
} });
_this.sessionToken = new google.maps.places.AutocompleteSessionToken();
if (_this.props.onSuggestSelect) {
_this.props.onSuggestSelect(suggest);
}
}
});
}
else {
var options = {
address: suggestToGeocode.label,
bounds: this.props.bounds,
componentRestrictions: this.props.country
? { country: this.props.country }
: undefined,
location: this.props.location
};
this.geocoder.geocode(options, function (results, status) {
if (status === _this.googleMaps.GeocoderStatus.OK) {
var gmaps = results[0];
var location_2 = gmaps.geometry.location;
var suggest = __assign({}, suggestToGeocode, { gmaps: gmaps, location: {
lat: location_2.lat(),
lng: location_2.lng()
} });
if (_this.props.onSuggestSelect) {
_this.props.onSuggestSelect(suggest);
}
var options = {
address: suggestToGeocode.label,
bounds: this.props.bounds,
componentRestrictions: this.props.country
? { country: this.props.country }
: undefined,
location: this.props.location
};
this.geocoder.geocode(options, function (results, status) {
if (status === _this.googleMaps.GeocoderStatus.OK) {
var gmaps = results[0];
var location_1 = gmaps.geometry.location;
var suggest = __assign({}, suggestToGeocode, { gmaps: gmaps, location: {
lat: location_1.lat(),
lng: location_1.lng()
} });
if (_this.props.onSuggestSelect) {
_this.props.onSuggestSelect(suggest);
}
});
}
}
});
};
/**
* Render the view
Expand Down
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