Created
June 17, 2014 01:22
-
-
Save drmmr763/4a3c6475bceeaa9ee678 to your computer and use it in GitHub Desktop.
Pass anonymous function result to parent function?
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
/* | |
* Takes a zipcode in string format | |
* Sends it to Google Maps API | |
* Returns an object containing latitude & longitude | |
*/ | |
function geocodeZipcode(zip) | |
{ | |
var geocodeOptions = | |
{ | |
'address': zip | |
} | |
// instiate the google map geocoder class | |
var geocoder = new google.maps.Geocoder(); | |
// places the results into a function | |
geocoder.geocode(geocodeOptions, function(results, status) { | |
// validate response and return location or error | |
if (status != google.maps.GeocoderStatus.OK) | |
{ | |
// something wasn't okay, send error message | |
return status; // exit early | |
} | |
var location = results[0].geometry.location; | |
// build json object | |
var latlong = | |
{ | |
'latitude': location.lat(), | |
'longitude': location.lng() | |
} | |
return latlong; | |
}); | |
// return ?? | |
// how to pass the return statements from the anonymous function as the geocodeZipcode function's return?? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So apparently the answer here is this thing called 'callbacks'. This is some mystical javascripty thingy that I don't understand yet. But somehow this works: