这是我正在使用的代码:http: //jsfiddle.net/9B84H/26/
function autosuggest() {
var input = document.getElementById('location');
var options = {types: [],};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
function getLatLng() {
var geocoder = new google.maps.Geocoder();
var address = document.getElementById('location').value;
geocoder.geocode({
'address': address
}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
$('#lat').val(results[0].geometry.location.lat());
$('#lng').val(results[0].geometry.location.lng());
} else {
alert("Geocode failed: " + status);
}
});
}
有两个变量几乎相同:
var address = document.getElementById('location').value;
var input = document.getElementById('location');
有没有机会将它组合成一行作为全局变量?