Created
July 17, 2013 20:11
-
-
Save danasilver/6024009 to your computer and use it in GitHub Desktop.
Revisions
-
danasilver created this gist
Jul 17, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ if (window.navigator.geolocation) { navigator.geolocation.getCurrentPosition(function (position) { var lat = position.coords.latitude, lng = position.coords.longitude, latlng = new google.maps.LatLng(lat, lng), geocoder = new google.maps.Geocoder(); geocoder.geocode({'latLng': latlng}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[1]) { for (var i = 0; i < results.length; i++) { if (results[i].types[0] === "locality") { var city = results[i].address_components[0].short_name; var state = results[i].address_components[2].short_name; $("input[name='location']").val(city + ", " + state); } } } else {console.log("No reverse geocode results.")} } else {console.log("Geocoder failed: " + status)} }); }, function() {console.log("Geolocation not available.")}); }