Get Latitude and Longitude Coods By jQuery and HTML 5 Geo-location API

Get Current Latitude and Longitude Coods By jQuery and HTML5 Geolocation API.

HTML5 Geolocation is used to get the geographical position of the user. When you get the visitor Latitude and Longitude, you can easily get the visitor country, state, city, and ZIP by Google Map.

Below the code for getting website user coords of latitude and longitude.

<script type="text/javascript">
jQuery(document).ready(function(){
    if(navigator.geolocation){
      var currentPosition = '';
      var lattitudePosition = '';
      var longitudePosition = '';
        
        navigator.geolocation.getCurrentPosition(function(position){
        currentPosition = position;
          console.log(currentPosition);
        lattitudePosition = currentPosition.coords.latitude;
        longitudePosition = currentPosition.coords.longitude;
          console.log(lattitudePosition);
          console.log(longitudePosition);
         });
                              }
                                });
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *