Last active
July 22, 2019 01:48
-
-
Save chaoswey/b522121d80f637b1a2b971505ffea4f4 to your computer and use it in GitHub Desktop.
jquery 查詢經緯度
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 characters
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=[key]&sensor=false"></script> | |
<script> | |
$(function () { | |
var geocoder = new google.maps.Geocoder; | |
$('#trans').on('click', function () { | |
var address = $('input[name=address]').val(); | |
geocoder.geocode({'address': address}, function (results, status) { | |
if (status === google.maps.GeocoderStatus.OK) { | |
var api = results[0].geometry.location; | |
$("input[name=lng]").val(api.lng); | |
$("input[name=lat]").val(api.lat); | |
} else { | |
console.log(status); | |
} | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment