Я пытаюсь получить широту и долготу с автозаполнения api google map, не показывая карту. В моем script автозаполнение работает хорошо, но я не могу получить широту и долготу.
<script type="text/javascript">
function initialize() {
var options = {
types: ['(cities)']
};
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
var geocoder = new google.maps.Geocoder();
var address = autocomplete;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
alert(latitude);
}
});
</script>