Skip to content

Instantly share code, notes, and snippets.

@lenafaure
Last active May 8, 2017 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lenafaure/b41781784a5a2ff5f6668d5dd354124c to your computer and use it in GitHub Desktop.
Save lenafaure/b41781784a5a2ff5f6668d5dd354124c to your computer and use it in GitHub Desktop.
// 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