Я создал следующий код, используя API Карт Google, который должен сделать линию направления на Картах Google между двумя заданными адресами. Мой код:Google Map Api Ошибка недопустимого значения
function initMap()
{
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: {lat: -34.397, lng: 150.644}
});
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer({
map: map
});
\t \t
var geocoder = new google.maps.Geocoder();
var pointA,pointB;
geocoder.geocode({'address': document.getElementById('addressFrom').value}, function(results, status) {
\t \t var location = results[0].geometry.location;
\t \t pointA = new google.maps.LatLng(location.lat(),location.lng());
\t \t alert(location.lat() + '' + location.lng());
\t \t });
\t \t
geocoder.geocode({'address': document.getElementById('addressTo').value}, function(results, status) {
\t \t var location = results[0].geometry.location;
\t \t pointB = new google.maps.LatLng(location.lat(),location.lng());
\t \t alert(location.lat() + '' + location.lng());
\t \t });
\t
\t var markerA = new google.maps.Marker({
position: pointA,
title: "point A",
label: "A",
map: map
});
\t
\t var markerB = new google.maps.Marker({
position: pointB,
title: "point B",
label: "B",
map: map
});
\t
\t calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB);
}
function calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB) {
directionsService.route({
origin: pointA,
destination: pointB,
travelMode: google.maps.TravelMode.DRIVING
}, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
<input id="addressFrom" type="textbox" value="Sydney">
<input id="addressTo" type="textbox" value="London">
<input id="submit" type="button" value="Geocode" onclick="initMap">
<div id="map"></div>
я получаю следующие ошибки при проверке из браузера:
возможно дубликат [Google Maps API Directions Service Отображение текста Направления Повторяющиеся] (http://stackoverflow.com/questions/38406549/google- maps-api-directions-service-display-text-direction-repeating) – geocodezip