Create a gist now

Instantly share code, notes, and snippets.

Embed
// Create array for storing results
var agencies = [];
function callback(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
//Fetch the ID of each Place returned by the Radar Search
var request = {
placeId: results[i]['place_id']
};
// Call the Places API Web Service
service = new google.maps.places.PlacesService(map);
// Initiate Place Details request
service.getDetails(request, callback);
function callback(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
createMarker(place);
agencies.push([place.name, place.website, place.rating]);
// When reaching the last result, send to PHP file to print results
if(results.length == agencies.length){
console.log(agencies);
var request = new XMLHttpRequest();
request.open('POST', 'http://localhost/agency-map/src/save.php', true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.send(JSON.stringify(agencies));
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment