This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 14th, 2013  |  syntax: None  |  size: 2.08 KB  |  views: 42  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var infowindow = new google.maps.InfoWindow();
  2.   var places=[];        //contains the addresses of markers
  3.  
  4. //Find User GeoLocation to Show On Map for the First TIme Map opens.
  5.     if (navigator.geolocation)
  6.     {
  7.             navigator.geolocation.getCurrentPosition(showPosition)                                                            
  8.     }
  9.     else
  10.     {
  11.             alert("Geolocation is not supported by this browser.");
  12.     }
  13.  
  14.     function showPosition(position)
  15.     {
  16.       latitude=position.coords.latitude;
  17.       longitude= position.coords.longitude;
  18.     }
  19.  
  20.  
  21. //Initialize Google Map Api
  22. function initialize()
  23. {
  24.     geocoder = new google.maps.Geocoder();
  25.  
  26.     //Initial Map Variables
  27.     var myoptions={
  28.             zoom:8,
  29.             center:new google.maps.LatLng(latitude,longitude),
  30.             mapTypeId:google.maps.MapTypeId.ROADMAP
  31.         };  
  32.  
  33.         //Initialize Map
  34.         map=new google.maps.Map(document.getElementById("map_canvas"),myoptions);          
  35.  
  36.     });
  37.  
  38. }
  39.        
  40. function getLocation() {
  41. var infowindow = new google.maps.InfoWindow();
  42.   var places=[];        //contains the addresses of markers
  43.  
  44. //Find User GeoLocation to Show On Map for the First TIme Map opens.
  45.     if (navigator.geolocation)
  46.     {
  47.         navigator.geolocation.getCurrentPosition(showPosition, function(err) { alert(err + " " + err.code);});
  48.     }
  49.     else
  50.     {
  51.             alert("Geolocation is not supported by this browser.");
  52.     }
  53. }
  54.  
  55.     function showPosition(position)
  56.     {
  57.       latitude=position.coords.latitude;
  58.       longitude= position.coords.longitude;
  59.       initialize(latitude, longitude);
  60.     }
  61.  
  62. //Initialize Google Map Api
  63. function initialize(latitude, longitude)
  64. {
  65.     geocoder = new google.maps.Geocoder();
  66.  
  67.     //Initial Map Variables
  68.     var myoptions={
  69.             zoom:8,
  70.             center:new google.maps.LatLng(latitude,longitude),
  71.             mapTypeId:google.maps.MapTypeId.ROADMAP
  72.         };  
  73.  
  74.         //Initialize Map
  75.         map=new google.maps.Map(document.getElementById("map_canvas"),myoptions);          
  76.  
  77. }
  78.        
  79. <body onload="getLocation()">
  80.  
  81. <div id="map_canvas"></div>
  82.  
  83. </body>
clone this paste RAW Paste Data