Advertisement
Guest User

gmap3 script

a guest
Aug 21st, 2012
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.            $(function (){
  3.            
  4.             var dest = "Unit 20, Tallaght Business Centre, Whitestown Road, Tallaght Business Park, Ireland";//53.282882, -6.383155
  5.            
  6.             if(geolocEnabled()){
  7.                 getLocation();
  8.             }else{
  9.                 plotMarker(dest);
  10.             }
  11.            
  12.             //check if geolocation enabled
  13.             function geolocEnabled(){
  14.                 return navigator.geolocation;
  15.             }
  16.            
  17.             //plot marker for VRF office
  18.             function plotMarker(dest){
  19.                 $('#map').gmap3(
  20.                   { action: 'addMarker',
  21.                     address: dest,
  22.                     map:{
  23.                       center: true,
  24.                       zoom: 14
  25.                     },
  26.                     marker:{
  27.                       options:{
  28.                         draggable: false
  29.                       }
  30.                     }
  31.                   }
  32.                 );
  33.             }
  34.            
  35.             //get user's location
  36.             function getLocation(){
  37.                 $('#map').gmap3(
  38.                 { action : 'geoLatLng',
  39.                   callback : function(latLng){
  40.                     if (latLng){
  41.                       plotRoute(latLng, dest);
  42.                       alert(latLng); //this alerts (53.34410399999999, -6.267493000000059), should be my exact location which is the same as 'dest'
  43.                       return;
  44.                     } else {
  45.                       alert("Unable to determine your location. Enable geolocation services and try again, or consult the map for our location.");
  46.                       $('#directions-panel').text("We were unable to give you directions. Please enable geolocation services on your device to see directions from your location to our office.");
  47.                       plotMarker(dest);
  48.                     }
  49.                   }
  50.                 });
  51.               }
  52.              
  53.             //plot route
  54.             function plotRoute(latLng, dest){
  55.             $('#map').gmap3(
  56.               { action:'getRoute',
  57.                 options:{
  58.                   origin: latLng,
  59.                   destination: dest,
  60.                   travelMode: google.maps.DirectionsTravelMode.DRIVING
  61.                 },
  62.                 callback: function(results){
  63.                   if (!results) return;
  64.                   $(this).gmap3(
  65.                     { action:'init',
  66.                       zoom: 7,
  67.                       mapTypeId: google.maps.MapTypeId.ROADMAP,
  68.                       streetViewControl: true,
  69.                       center: [53.337433,-6.2661]
  70.                     },
  71.                     { action:'addDirectionsRenderer',
  72.                       panelID: 'directions-panel',
  73.                       options:{
  74.                         preserveViewport: true,
  75.                         draggable: false,
  76.                         directions:results
  77.                       }
  78.                     },
  79.                     { action: "autofit"}
  80.                   );
  81.                 }
  82.               }
  83.             );
  84.           }
  85.    
  86.         });
  87.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement