Last active
May 8, 2017 09:12
-
-
Save lenafaure/b41781784a5a2ff5f6668d5dd354124c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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