Answer the question
In order to leave comments, you need to log in
Why can't I get directions on the map?
I want to build a route on the map from the user specified in the "start" field to the place that I specify.
There is a map:
<section id="cd-google-map">
<div id="google-container"></div>
<div id="cd-zoom-in"></div>
<div id="cd-zoom-out"></div>
</section>
<form action="" onsubmit="calcRoute();" id="start">
<input type="text" id="start" value="">
<input type="submit" value="Проложить маршрут">
</form>
jQuery(document).ready(function($){
//set your google maps parameters
var latitude = 59.938615,
longitude = 30.36936,
map_zoom = 17;
var style= [//какие-то стили]
//set google map options
var map_options = {
center: new google.maps.LatLng(latitude, longitude),
zoom: map_zoom,
panControl: false,
zoomControl: false,
mapTypeControl: false,
scrollwheel: false,
styles: style,
}
//init map
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
var map = new google.maps.Map(document.getElementById('google-container'), map_options);
directionsDisplay.setMap(map);
function calculateAndDisplayRoute(directionsService, directionsDisplay) {
directionsService.route({
origin: document.getElementById('start').value,
destination: "59.938615,30.36936",
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);
}
});
}
});
Answer the question
In order to leave comments, you need to log in
In general, I didn’t understand why it didn’t work - it seemed like I did everything according to the example from Google .. But I found a ready-made and working example - tyts
Mb will come in handy for someone.
onsubmit="calcRoute();"
And where is the function itself with this name?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question