I am quite far into my final project and needed either a database or software which would return places when given a keyword and an area as input. E.g. Restaurants in London.
I tried using the Google Maps Javascript Places API which does just that and have copied google's documentation, however it doesn't successfully run. There is no error message either.
This is the url for the documentation: https://developers.google.com/maps/documentation/javascript/places#find_place_from_query
alert("1");
var request = {
query: 'Restaurant',
fields: ['formatted_address', 'name', 'rating', 'geometry'],
};
alert("2");
service = new google.maps.places.PlacesService(map);
alert("3");
service.findPlaceFromQuery(request, callback);
alert("success");
Only the first two alerts are received. Here is the callback function which is required as a parameter for the query:
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
addMarker(place);
}
}
}
This is all in a file called scripts.js
which also contains a Google Map (which runs completely normally). I'm not sure whether I need to store the API Key in the code because, my Google Map runs fine without one.
Please can someone either tell me what my problem is or suggest another way to perform this job.