javascript - How to Get Current Address accurately using Google Maps? -


im trying current location problem address marker points nearest street now. how can place accurately?

heres screen shot. in advance :) click here

<input type="button" value="show location" onclick="showlocation()"/>   <br/>     latitude: <span id="latitude">..</span> <br>     longitude: <span id="longitude">..</span><br>     address: <span id="add">..</span><br>     <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>      <script>      function showlocation(){          navigator.geolocation.watchposition(callback);      }     function callback(position){         document.getelementbyid('latitude').innerhtml=position.coords.latitude;         document.getelementbyid('longitude').innerhtml=position.coords.longitude;           var geocoder = new google.maps.geocoder();           var latitude = position.coords.latitude;           var longitude = position.coords.longitude;           var latlng = new google.maps.latlng(latitude,longitude);         geocoder.geocode({                    latlng: latlng                  },              function(responses)              {                     if (responses && responses.length > 0)                 {                            address(responses[0].formatted_address);                     }                 else                 {                         alert('not getting address given latitude , longitude.');                     }                }     );     }          function address(str)          {           document.getelementbyid('add').innerhtml = str;         }      </script> 

use geolocation api. obtain current location, can call getcurrentposition() method. initiates asynchronous request detect user's position, , queries positioning hardware up-to-date information.

when position determined, defined callback function executed. can optionally provide second callback function executed if error occurs. third, optional, parameter options object can set maximum age of position returned, time wait request, , if want high accuracy position.

this documentation , example might you.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -