Skip to content

Instantly share code, notes, and snippets.

@Borodin
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save Borodin/2ebd40e7b7480be43af3 to your computer and use it in GitHub Desktop.

Select an option

Save Borodin/2ebd40e7b7480be43af3 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px;
}
#map-canvas{
/*height: 50%*/
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
var map, directionsDisplay;
//"DRIVING", "WALKING", "BICYCLING", "TRANSIT"
function getDirections(origin, destination, travelMode){
if(directionsDisplay != null) {
directionsDisplay.setMap(null);
directionsDisplay = null;
}
var directionsService = new google.maps.DirectionsService();
directionsService.route({
origin: origin,
destination: destination,
travelMode: travelMode||"DRIVING"
}, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
directionsDisplay.setDirections(response);
}else{
alert('Маршрут не найден');
}
}
)
}
function initialize() {
var mapOptions = {
zoom: 8,
disableDefaultUI: true,
center: new google.maps.LatLng(-34.397, 150.644)
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
getDirections('Москва Новинки 3', 'Воронеж', 'WALKING');
//getDirections('Москва Новинки 3', 'Новгород')
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment