Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Google Maps » Geolocation API + Directions API</title>
- <style type="text/css">
- body {
- margin-left: 0px;
- margin-top: 0px;
- margin-right: 0px;
- margin-bottom: 0px;
- }
- #mapa {
- width:100%;
- height:400px;
- }
- </style>
- <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
- <script type="text/javascript">
- var pri = '-27.395195';
- var sec = '-53.428319';
- if (navigator.geolocation) { //Checks if browser supports geolocation
- navigator.geolocation.getCurrentPosition(function (position) { //This gets the
- var latitude = position.coords.latitude; //users current
- var longitude = position.coords.longitude; //location
- var coords = new google.maps.LatLng(latitude, longitude); //Creates variable for map coordinates
- var directionsService = new google.maps.DirectionsService();
- var directionsDisplay = new google.maps.DirectionsRenderer();
- var mapOptions = //Sets map options
- {
- zoom: 15, //Sets zoom level (0-21)
- center: coords, //zoom in on users location
- mapTypeControl: false, //allows you to select map type eg. map or satellite
- disableDefaultUI: true, //Disabling the default UI
- /*navigationControlOptions:
- {
- style: google.maps.NavigationControlStyle.SMALL //sets map controls size eg. zoom
- },*/
- mapTypeId: google.maps.MapTypeId.ROADMAP //sets type of map Options:ROADMAP, SATELLITE, HYBRID, TERRIAN
- };
- map = new google.maps.Map( /*creates Map variable*/ document.getElementById("mapa"), mapOptions /*Creates a new map using the passed optional parameters in the mapOptions parameter.*/);
- directionsDisplay.setMap(map);
- directionsDisplay.setPanel(document.getElementById('rota'));
- var request = {
- origin: coords,
- //destination: 'BT42 1FL',
- //destination:new google.maps.LatLng(-27.395195, -53.428319),
- destination:new google.maps.LatLng(''+pri+'', ''+sec+''),
- //destination:new google.maps.LatLng(pri, sec),
- travelMode: google.maps.DirectionsTravelMode.DRIVING
- };
- directionsService.route(request, function (response, status) {
- if (status == google.maps.DirectionsStatus.OK) {
- directionsDisplay.setDirections(response);
- }
- });
- });
- }
- </script>
- </head>
- <body>
- <div id="mapa"></div>
- <div id="rota"></div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment