Usually, there is a need to get the directions based on given latitudes and longitude. After a good healthy search found something interesting which I wished to share.
You can view the example on JS Fiddle: http://jsfiddle.net/SurajMindfire/7utktkp4/.
- <!DOCTYPE html>
- <html>
- <head>
- <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
- </head>
- <body>
- <div id="map"></div>
- </body>
- </html>
-
- $(document).ready(function() {
- var myOptions = {
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- mapTypeControl: false,
- panControl: false,
- zoomControl: true,
- zoomControlOptions: {
- style: google.maps.ZoomControlStyle.LARGE,
- position: google.maps.ControlPosition.LEFT_CENTER
- },
- scaleControl: false,
- streetViewControl: false,
- };
- var map = new google.maps.Map($("#map")[0], myOptions),
- directionsService = new google.maps.DirectionsService(),
- directionsDisplay = new google.maps.DirectionsRenderer({map:map});
- new google.maps.Marker({
- position: new google.maps.LatLng(26.968468, 23.766233),
- map: map
- });
- var request = {
- origin: new google.maps.LatLng(40.962200, 23.615602),
- destination: new google.maps.LatLng(37.968468, 23.766233),
- travelMode: google.maps.TravelMode.DRIVING
- };
- directionsService.route(request,
- function(response, status) {
- if (status == google.maps.DirectionsStatus.OK) {
- directionsDisplay.setDirections(response);
- }
- });
- });
-
- #map{
- width:500px;
- height:500px;
- }
Hope this helps.