Saturday, 12 March 2016

How to trace your current location useing Gogle map API in brrowser ?





<!DOCTYPE html>


<html>
   
   <head>
      <script src = "http://maps.googleapis.com/maps/api/js"></script>
     
      <script>
      var dataX='place yr info here..';
      //alert(dataX);
   function getLocation() {
    if (navigator.geolocation){
        navigator.geolocation.getCurrentPosition(loadMap);
    } else { 
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
                    }
         function loadMap(position){
    var lati=position.coords.latitude; 
    var lang=position.coords.longitude;
            var mapOptions = {
               center:new google.maps.LatLng(lati,lang),
               zoom:17
            }
            
            var map = new google.maps.Map(document.getElementById("sample"),mapOptions);
            
            var marker = new google.maps.Marker({
               position: new google.maps.LatLng(lati,lang),
               map: map,
               draggable:false,
               icon:"https://lh6.googleusercontent.com/-jceMtMC7nk4/AAAAAAAAAAI/AAAAAAAAABQ/WOlkICkIH7c/photo.jpg?sz=50"
               });
            
            marker.setMap(map);
            
            var infowindow = new google.maps.InfoWindow({
               content:dataX
            });
    
            infowindow.open(map,marker);
         }
      </script>
      
   </head>
   
   <body onload = "getLocation()">
      <div id = "sample" style = "width:100%; height:400px; " ></div>
   </body>
   
</html>
 


It will work as..





   
   
      
     
      
      
   
   
   
      

No comments:

Post a Comment