Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  7] [ 7]  / answers: 1 / hits: 22241  / 14 Years ago, fri, november 12, 2010, 12:00:00

I have lat/lon for 2 places. How to get directions from google maps api?
I want to show map and directions text.


More From » google-maps

 Answers
49
<!DOCTYPE html>
<html>
<head>
<meta name=viewport content=initial-scale=1.0, user-scalable=no/>
<meta http-equiv=content-type content=text/html; charset=UTF-8/>
<link href=http://code.google.com/apis/maps/documentation/javascript/examples/default.css rel=stylesheet type=text/css />
<script type=text/javascript src=http://maps.google.com/maps/api/js?sensor=false></script>
<script type=text/javascript>
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var myOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
}
map = new google.maps.Map(document.getElementById(map_canvas), myOptions);
directionsDisplay.setMap(map);

var start = '37.7683909618184, -122.51089453697205';
var end = '41.850033, -87.6500523';
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var myRoute = response.routes[0];
var txtDir = '';
for (var i=0; i<myRoute.legs[0].steps.length; i++) {
txtDir += myRoute.legs[0].steps[i].instructions+<br />;
}
document.getElementById('directions').innerHTML = txtDir;
}
});
}
</script>
</head>
<body onload=initialize()>
<div id=directions style=width:500px;height:500px;float:left></div>
<div id=map_canvas style=width:500px;height:500px;></div>
</body>
</html>

[#94992] Wednesday, November 10, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dewayneh

Total Points: 538
Total Questions: 114
Total Answers: 97

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
dewayneh questions
Sat, Sep 4, 21, 00:00, 3 Years ago
Sun, Nov 1, 20, 00:00, 4 Years ago
Wed, Sep 23, 20, 00:00, 4 Years ago
Fri, Aug 7, 20, 00:00, 4 Years ago
Wed, Jul 29, 20, 00:00, 4 Years ago
;