2013-08-31 5 views
0

Я просматриваю gmap3 plugin для google map. Здесь у меня есть код longitude value and latitude value с кодом карты google. Теперь я хочу адрес таких значений, как country name state name and city name etc. Итак, как получить эти значения от longitude and latitude значений. Мой код выглядит следующим образом:Google map получить общий адрес от значений долготы и широты

jQuery(document).ready(function() { 
    jQuery('#map').blur(function() { 
    //console.log('hello'); 
    var the_address = jQuery(this).val(); 
    var geocoder = new google.maps.Geocoder(); 
    var latLng = geocoder.geocode({ 
     address: the_address 
    }, function(results, status) { 

    /// IF WE HAVE A RESULT 
    if(status == google.maps.GeocoderStatus.OK) { 
    lat = results[0].geometry.location.lat(); 
    lng = results[0].geometry.location.lng(); 
    jQuery('#latitude').val(lat); 
    jQuery('#longitude').val(lng); 

    jQuery(gMap).gmap3({ 
     get: { 
     name: 'marker', 
     all: true, 
     callback: function(objs) { 
      jQuery.each(objs, function(i, obj) { 
      obj.setMap(null); 
      }) 
     } 
     }, 
     map: { 
     options: { 
      zoom: 10, 
      center: new google.maps.LatLng(lat, lng) 
     } 
     }, 
     marker: { 
      values: [{ latLng:[lat, lng] }], 
      //jQuery(console.log(values)); 
      options: { 
      draggable: true, 
      icon: new google.maps.MarkerImage(
      "http://gmap3.net/skin/gmap/magicshow.png", 
      new google.maps.Size(32, 37, "px", "px") 
      ), 
      }, 
      events: { 
      mouseup: function(marker, event, context) { 
       //// GETS MARKER LATITUDE AND LONGITUDE 
       var thePos = marker.getPosition(); 
       var theLat = thePos.jb; 
       var theLng = thePos.kb; 
       jQuery('#latitude').val(theLat); 
       jQuery('#longitude').val(theLng); 
      }, 
      dragend: function(marker, event, context) { 
      jQuery(this).gmap3({ 
       getaddress:{ 
       latLng:marker.getPosition(), 
       callback:function(results){ 
        var map = $(this).gmap3("get"), 
        infowindow = $(this).gmap3({get:"infowindow"}), 
        content = results && results[1] ? results && results[1].formatted_address : "no address"; 
        if (infowindow){ 
        infowindow.open(map, marker); 
        infowindow.setContent(content); 
        } else { 
        jQuery(this).gmap3({ 
        infowindow:{ 
        anchor:marker, 
        options:{content: content} 
        } 
       }); 
       } 
      } 
      } 
     }); 
      }, 

     } 
     } 
    }); 
     } else { 
     alert('Could not find the latitude and longitude for the address '+the_address); 
       } 
     }); 
    }); 
}); 

Любая помощь и предложения будут действительно заметны. Спасибо

+0

Где вы хотите, чтобы получить это? Вы можете просто изменить геокод с помощью Lat и Lng, чтобы получить полный адрес. – putvande

ответ

0

Я не уверен, где вы хотите иметь полный адрес, но его легко получить. Если вы хотите получить результат от вашего Geocoder, вы можете получить полный адрес, позвонив по телефону results[0].formatted_address.

Если вы хотите, чтобы получить адрес, просто заполнив широты и длинные значения, которые вы можете сделать обратный Геокодировать:

var geocoder = new google.maps.Geocoder(); 
geocoder.geocode({ 'latLng': new google.maps.LatLng(lat,lon) }, function(results, status){ 
    console.log(results[0].formatted_address); 
}); 

https://developers.google.com/maps/documentation/javascript/geocoding?hl=nl#ReverseGeocoding

Смежные вопросы