Skip to content

Instantly share code, notes, and snippets.

@amitittyerah
Created April 24, 2014 00:15
Show Gist options
  • Save amitittyerah/11237047 to your computer and use it in GitHub Desktop.
Save amitittyerah/11237047 to your computer and use it in GitHub Desktop.
Get bounds from the Google Maps Autocomplete response
function get_bounds(gmaps_autocomplete_response) {
var lats = false, longs = false;
$.each(gmaps_autocomplete_response.geometry.viewport, function () {
if (!lats || !longs) {
var x,y = false;
var ref = false;
$.each(this, function () {
if (!x || !y) {
if (!x) x = this;
else y = this;
} else {
ref = {x: x, y: y};
}
});
if (!lats) lats = ref;
else longs = ref;
}
});
return {latitudes: lats, longitudes: longs};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment