Created
March 19, 2016 21:55
-
-
Save adamgibbons/f72cb712fac7554b8d37 to your computer and use it in GitHub Desktop.
get client's zip code (first five)
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
window.navigator.geolocation.getCurrentPosition(function(pos){ | |
$.get('//maps.googleapis.com/maps/api/geocode/json?latlng='+pos.coords.latitude+','+pos.coords.longitude+'&sensor=true') | |
.then(function(res){ | |
var postalCode = res.results.filter(function (result) { | |
return result.types.indexOf('postal_code') !== -1; | |
})[0]; | |
var formattedPostalCode = postalCode.address_components.filter(function(component) { | |
return component.types.indexOf('postal_code') !== -1; | |
}).map(function(postalCode) { | |
return postalCode.long_name; | |
})[0]; | |
return formattedPostalCode; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment