2012-11-03 4 views
0

미성년자 용 Google 지오 코딩 스크립트를 찾으려고합니다. 내가 찾은 것들은 매우 크고 복잡하지만, 이것은 매우 간단합니다. 그것이하지 않는 유일한 것은 실제로 다른 것과 같이 두 개의 입력 상자에 좌표를 넣습니다. 나는 그것이 긴/위도 입력 필드에 좌표를 넣어 어떻게합니까 http://jsfiddle.net/Rr5PL/89/Google 지오 코더 - 입력란에 좌표 추가

: 여기

는 코드 작동합니까? 지도에 표시 할 때 사용하기 때문에 저장해야합니다.

var geocoder; 
    var map; 
    function initialize() { 
    geocoder = new google.maps.Geocoder(); 
    var latlng = new google.maps.LatLng(-34.397, 150.644); 
    var mapOptions = { 
     zoom: 8, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); 
    } 

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

왜 입력란에 입력 하시겠습니까? 이미 변수에 저장되어 있습니다. – Marcelo

+0

URL을 URL (예 : www.url.com/search?long=123lat=456 – Jimmy

+0

)로 전달하고 싶습니다. Javascript 변수에서 가져올 수 있습니다. 입력 필드가 필요하지 않습니다. – Marcelo

답변

1

Javascript 변수에서 가져올 수 있습니다. 입력 필드가 필요하지 않습니다.

var lat = results[0].geometry.location.lat(); 
var lon = results[0].geometry.location.lng(); 
var url = 'www.url.com/search?lon='+lon+'&lat='+lat; 
1

텍스트 필드에 위도와 경도를 입력하려면 먼저 2 개의 텍스트 상자를 만들고 위도와 경도를 입력해야합니다.

var latitude= results[0].geometry.location.lat(); 
var longitude=results[0].geometry.location.lng(); 

이 jsfiddle는 예를 보여줍니다. http://jsfiddle.net/harendra/njDvn/6/

1

그것은 쉽게,이

var loc=results[0].geometry.location; 
document.getElementById('latLng').value=loc.lat()+', '+loc.lng(); 

DEMO을 시도합니다.

+1

.cb 또는 .eb과 같은 문서화되지 않은 속성을 사용하지 마십시오. 이러한 이름은 이름이 축소되어 있으며 향후 API 릴리스에서 예고없이 변경 될 수 있습니다. – Marcelo

+0

@Marcelo, 당신 말이 맞아요. –

관련 문제