Advertisement
fahmihilmansyah

asa

Jul 5th, 2013
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  5.    <title>Google Maps API v3 Directions Example</title>
  6.    <script type="text/javascript"
  7.            src="http://maps.google.com/maps/api/js?sensor=false"></script>
  8. </head>
  9. <body style="font-family: Arial; font-size: 12px;">
  10.    <div style="width: 600px;">
  11.      <div id="map" style="width: 280px; height: 400px; float: left;"></div>
  12.      <div id="panel" style="width: 300px; float: right;"></div>
  13.    </div>
  14.  
  15.    <script type="text/javascript">
  16.  
  17.      var directionsService = new google.maps.DirectionsService();
  18.      var directionsDisplay = new google.maps.DirectionsRenderer();
  19.  
  20.      var map = new google.maps.Map(document.getElementById('map'), {
  21.        zoom:7,
  22.        mapTypeId: google.maps.MapTypeId.ROADMAP
  23.      });
  24.  
  25.      directionsDisplay.setMap(map);
  26.      
  27.      directionsDisplay.setPanel(document.getElementById('panel'));
  28.      
  29.     //posisi saat ini
  30.      var abcd=navigator.geolocation.getCurrentPosition(function(position) {
  31.       var pos = new google.maps.LatLng(position.coords.latitude,
  32.                                        position.coords.longitude);
  33.     console.log(pos);
  34.         });
  35.                                        
  36.      var tujuan = new google.maps.LatLng(-6.938664, 107.623672);//-34.397, 150.644);
  37.      var request = {
  38.        origin: abcd, //mengambil posisi saat ini
  39.        destination: 'bandung',//abcd,//'Bandung',
  40.        travelMode: google.maps.DirectionsTravelMode.DRIVING
  41.      };
  42.      directionsService.route(request, function(response, status) {
  43.        if (status == google.maps.DirectionsStatus.OK) {
  44.          directionsDisplay.setDirections(response);
  45.          
  46.        }else{
  47.         alert("Lintas Lautan bro");
  48.        }
  49.      });
  50.    </script>
  51. </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement