Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- $(function (){
- var dest = "Unit 20, Tallaght Business Centre, Whitestown Road, Tallaght Business Park, Ireland";//53.282882, -6.383155
- if(geolocEnabled()){
- getLocation();
- }else{
- plotMarker(dest);
- }
- //check if geolocation enabled
- function geolocEnabled(){
- return navigator.geolocation;
- }
- //plot marker for VRF office
- function plotMarker(dest){
- $('#map').gmap3(
- { action: 'addMarker',
- address: dest,
- map:{
- center: true,
- zoom: 14
- },
- marker:{
- options:{
- draggable: false
- }
- }
- }
- );
- }
- //get user's location
- function getLocation(){
- $('#map').gmap3(
- { action : 'geoLatLng',
- callback : function(latLng){
- if (latLng){
- plotRoute(latLng, dest);
- alert(latLng); //this alerts (53.34410399999999, -6.267493000000059), should be my exact location which is the same as 'dest'
- return;
- } else {
- alert("Unable to determine your location. Enable geolocation services and try again, or consult the map for our location.");
- $('#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.");
- plotMarker(dest);
- }
- }
- });
- }
- //plot route
- function plotRoute(latLng, dest){
- $('#map').gmap3(
- { action:'getRoute',
- options:{
- origin: latLng,
- destination: dest,
- travelMode: google.maps.DirectionsTravelMode.DRIVING
- },
- callback: function(results){
- if (!results) return;
- $(this).gmap3(
- { action:'init',
- zoom: 7,
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- streetViewControl: true,
- center: [53.337433,-6.2661]
- },
- { action:'addDirectionsRenderer',
- panelID: 'directions-panel',
- options:{
- preserveViewport: true,
- draggable: false,
- directions:results
- }
- },
- { action: "autofit"}
- );
- }
- }
- );
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement