Javascript Function - Convert Geolocation Code to Street Address

I am looking for a javascript function or jquery library to convert geolocation code (e.g. 42.2342,32.23452) to a street address

For instance.

    navigator.geolocation.getCurrentPosition(
      function(pos) {
        $("#lat_field").val(pos.coords.latitude);
        $("#long_field").val(pos.coords.longitude);
      }
    );

Here is the Google API URL to get the address data

http://maps.googleapis.com/maps/api/geocode/json?latlng=41.03531125,29.0124264&sensor=false

I want to see "formatted_address": "Hacı Hesna Hatun Mh., Paşa Limanı Cd 2-26, 34674 Istanbul, Türkiye",

    navigator.geolocation.getCurrentPosition(
      function(pos) {
        $("#lat_field").val(pos.coords.latitude);
        $("#long_field").val(pos.coords.longitude);
        $("#adress_data").getaddrfromlatlong(pos.coords.latitude,pos.coords.longitude)
      }
    );

This function should be like? '' Getaddrfromlatlong ()

+5
source share
2 answers

Try the following:

<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">     
   var geocoder = new google.maps.Geocoder();
   var latLng = new google.maps.LatLng(41.03531125,29.0124264);

   if (geocoder) {
      geocoder.geocode({ 'latLng': latLng}, function (results, status) {
         if (status == google.maps.GeocoderStatus.OK) {
            console.log(results[0].formatted_address);
         }
         else {
            console.log("Geocoding failed: " + status);
         }
      });
   }    
</script>
+8
source

Javascript, - - google maps XML . JSON, , , . ( , grep), , .

0

All Articles