구글 맵에서 Lat, Long을 구해서 여분 필드에 넣기 > 개발자팁

개발자팁

개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.

구글 맵에서 Lat, Long을 구해서 여분 필드에 넣기 정보

JavaScript 구글 맵에서 Lat, Long을 구해서 여분 필드에 넣기

첨부파일

geocoding-simple.htm (1.7K) 15회 다운로드 2012-01-08 13:13:52

본문

구글 맵에서 주소를 이용해서 위도, 경도를 구해서 여분필드에 저장 하고 싶습니다.
아래에 있던 마커가 모두 위도, 경도로 구하는 샘플이라서..
주소에서 직접 마커 찍도록 바꾸는 것이 어려워서 그냥 여분필드에 미리 위도,경도를 구해서 저장해 놓을 까 합니다.
 
첨부 파일의 중간쯤 보면
         alert("1: " + results[0].geometry.location.lat());
         alert("2: " + results[0].geometry.location.lng());
가 있는데,  이부분을 게시판의 여분 필드 wr_3, wr_4에 저장하면 됩니다. (write_skin.php에서)
 
고수님들의 조언 부탁드립니다.
추천
0
  • 복사

댓글 1개

<script type="text/javascript">
  var geocoder;
  var map;
  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(36.778, -119.4179);
    var myOptions = {
      zoom: 12,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  }

  function codeAddress() {
    var address = document.getElementById("wr_1").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
document.getElementById("wr_8").value= results[0].geometry.location.lat();
document.getElementById("wr_9").value= results[0].geometry.location.lng();
        var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }
</script>

이런식으로 이용하시면 될실거 같습니다..
© SIRSOFT
현재 페이지 제일 처음으로