В настоящее время я пытаюсь использовать API геокодирования Google для преобразования адреса в координаты Lat/Lng, однако при использовании примера в своей документации для разработчиков (https://developers.google.com/maps/documentation/javascript/geocoding) я сталкиваюсь с ошибка «InvalidValueError: неизвестная функция свойства»API Карт Google: Geocoder: неизвестная функция свойства:
В моем файле HTML у меня есть вызов API карты google и карты div, где должна отображаться моя карта. (Конечно, у меня есть другие вещи тоже, но только ради получения прямо в точку я буду размещать только соответствующий код)
<script src="https://maps.googleapis.com/maps/api/js?key=APIKEY&callback=initMap" async defer></script>
<div id="map"></div>
И в моем JS файл:
window.initMap = function(){
var fromLocation = new google.maps.LatLng(37.09024, -95.712891),
destLocation = new google.maps.LatLng(37.09024, -95.712891),
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 37.09024 , lng: -95.712891}, // center of USA
zoom: 4 // continet level
}),
directionService = new google.maps.DirectionsService(),
directionRender = new google.maps.DirectionsRenderer({
map: map
}),
markerA = new google.maps.Marker({
position: fromLocation,
title: "Point A",
label: "From",
map:map
}),
markerB = new google.maps.Marker({
position: destLocation,
title: "Point B",
label:"Destination",
map:map
});
getLatLng("Los Angeles");
} // end of initMap
function getLatLng(address){
geocoder = new google.maps.Geocoder();
geocoder.geocode({address: address, function(results,status){
if(status === 'OK'){
console.log(results[0].geometry.location);
}
else{
console.log("Geocoding couldn't convert string address to lat/long points");
}
}
});// end of geocoder method.
}
Любая идея о том, как исправить неизвестную ошибку функции свойства? Спасибо!