Breaking

how to get current location of client using javascript



Geolocation is the identification of the real-world geographic location of an object, such as a radar source, mobile phone or Internet-connected computer terminal. 

Geolocation may refer to the practice of assessing the location, or to the actual assessed location.


we are going to get exact location of client using javascript .

below code you can get total array of data you can use it as you want ..

Just Run this code in your any html or other page .

$(function () { 
            function onPositionUpdate(position) { 
                     var lat = position.coords.latitude;
                      var lng = position.coords.longitude;

                      console.log("http://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lng + "&sensor=true"); 
                   var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lng + "&sensor=true"; 

                 $.getJSON(url, {
                          format: "json" 
                     }).done(function (data) {
                            console.log(data); 
                     }); 
                  } 


               if (navigator.geolocation) {
  
                    navigator.geolocation.getCurrentPosition(onPositionUpdate); 
               } else { 
                      console.log("navigator.geolocation is not available");
                     } 
     })();

No comments:

Powered by Blogger.