2013-08-31 6 views
0

Google지도는 gmap3 plugin입니다. 여기에 Google지도 코드에서 longitude value and latitude value이 있습니다. 이제이 값의 주소를 country name state name and city name etc과 같이 입력하겠습니다. 그렇다면이 값을 longitude and latitude 값에서 가져 오는 방법. 내 코드는 다음과 같습니다.Google지도는 경도와 위도 값의 총 주소를 얻습니다.

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

관련 문제