Reputation: 87
I am hoping to provide a specific function in my app. I want to be able to enter an address, or use an address stored in a database e.g. "119 Harley Street, London" or "119 Harley Street" (this is just a random address to illustrate my requirements taken from the Google Places 'vicinity' field relating to a business called "The London Clinic Eye Centre").
Based on the address entered, I would like to be able to identify the Business Name at this address, if there is one, so the 'name' field in the Places JSON result, and also identify if there are any recent reviews by customers, with Date/Time and the review itself, photos etc.
Is this at all possible, or am I looking for something that isn't possible? I have experience of using other Google APIs (Geolocation & JS) but this is a new one to me, and can't see any way of achieving this from the documentation - I hope I am missing something.
Can anyone help? An alternative way of achieving what I need would also be much appreciated.
Many thanks in advance.
Upvotes: 2
Views: 2868
Reputation: 4840
Looks like you want something like the At this location in Google Maps (example):
This is not exactly available in the same way in the Places API, but I think you can use Nearby Search to get pretty close:
location
, no keyword
, and rankby=distance
Example Nearby Search request for "Bahnhofstrasse 30 Zurich", which geocodes to 47.3705904,8.5391694:
Results (name, vicinity):
Upvotes: 1
Reputation: 18125
Here is a little snippet straight from Google that show you how to use the "prediction" API to get a list of suggested places:
function initCallback() {
var getDetailsCallback = function(place, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
alert(status);
return;
}
// write details of place to console
console.log('Place');
console.log(place);
};
var getQueryPredictionsCallback = function(predictions, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
alert(status);
return;
}
// write predictions to the console
console.log('Predictions');
console.log(predictions);
// get details of each prediction
var map = new google.maps.Map(document.createElement('div'));
var placesService = new google.maps.places.PlacesService(map);
predictions.forEach(function(prediction) {
placesService.getDetails({ placeId: prediction.place_id }, getDetailsCallback);
});
};
var autocompleteService = new google.maps.places.AutocompleteService();
autocompleteService.getQueryPredictions({ input: '119 Harley Street' }, getQueryPredictionsCallback);
}
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?&libraries=places&callback=initCallback" async defer></script>
Upvotes: 0