daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var initialLocation;
  2.     var siberia = new google.maps.LatLng(44.9111410149792, -93.0537195);
  3.     var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
  4.     var browserSupportFlag =  new Boolean();
  5.  
  6.  
  7.  
  8.     function initialize() {
  9.         var myOptions = {
  10.             zoom: 6,
  11.             mapTypeId: google.maps.MapTypeId.HYBRID
  12.         };
  13.         var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  14.  
  15.         myListener = google.maps.event.addListener(map, 'click', function(event) {
  16.             placeMarker(event.latLng);
  17.             google.maps.event.removeListener(myListener);
  18.         });
  19.         google.maps.event.addListener(map, 'drag', function(event) {
  20.             placeMarker(event.latLng);
  21.             google.maps.event.removeListener(myListener);
  22.         });
  23.  
  24.         // Try W3C Geolocation (Preferred)
  25.         if(navigator.geolocation) {
  26.             browserSupportFlag = true;
  27.             navigator.geolocation.getCurrentPosition(function(position) {
  28.                 initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
  29.                 map.setCenter(initialLocation);
  30.             }, function() {
  31.                 handleNoGeolocation(browserSupportFlag);
  32.             });
  33.             // Try Google Gears Geolocation
  34.         } else if (google.gears) {
  35.             browserSupportFlag = true;
  36.             var geo = google.gears.factory.create('beta.geolocation');
  37.             geo.getCurrentPosition(function(position) {
  38.                 initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
  39.                 map.setCenter(initialLocation);
  40.             }, function() {
  41.                 handleNoGeoLocation(browserSupportFlag);
  42.             });
  43.             // Browser doesn't support Geolocation
  44.         } else {
  45.             browserSupportFlag = false;
  46.             handleNoGeolocation(browserSupportFlag);
  47.         }
  48.  
  49.         function handleNoGeolocation(errorFlag) {
  50.             if (errorFlag === true) {
  51.                 alert("Geolocation service failed.");
  52.                 initialLocation = newyork;
  53.             } else {
  54.                 alert("Your browser doesn't support geolocation. We've placed you in beautiful Minneapolis.");
  55.                 initialLocation = siberia;
  56.             }
  57.                 map.setCenter(initialLocation);
  58.  
  59.         }
  60.  
  61.         function placeMarker(location) {
  62.             var marker = new google.maps.Marker({
  63.                 position: location,
  64.                 map: map,
  65.                 draggable: true
  66.             });
  67.             map.setCenter(location);
  68.             var markerPosition = marker.getPosition();
  69.             populateInputs(markerPosition);
  70.             google.maps.event.addListener(marker, "drag", function (mEvent) {
  71.                 populateInputs(mEvent.latLng);
  72.             });
  73.         }
  74.         function populateInputs(pos) {
  75.             document.getElementById("t1").value=pos.lat()
  76.             document.getElementById("t2").value=pos.lng();
  77.         }
  78.     }
  79.    
  80. function placeMarker(location) {
  81.             var marker = new google.maps.Marker({
  82.                 position: location,
  83.                 map: map,
  84.                 draggable: true
  85.             });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top