2011-11-24 5 views
0

위도와 경도 값을 텍스트 상자로 가져올 수없는 이유는 무엇입니까? 내 텍스트 상자 값이 표시되지 않습니다. 비슷한 방식으로 <span id="lat">을 사용하면 위도와 경도 값을 볼 수 있습니다./:GoogleMap v3 - 데이터 추출

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Gecoding</title> 
<style type="text/css"> 
    html { height: 100% } 
    body { height: 100%; margin: 0; padding: 0 } 
    #map { height: 100% } 
</style> 
<script type="text/javascript" 
    src="http://maps.googleapis.com/maps/api/js?sensor=true&v=3&libraries=geometry"> 
</script> 
<script type="text/javascript"> 
var geocoder; 
    var map; 
    var marker; 
    function initialize() 
    { 
    geocoder = new google.maps.Geocoder(); 
    var latlng = new google.maps.LatLng(17.447246,78.362029); 
    var myOptions = 
     { 
      zoom: 8, 
       center: latlng, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      } 
     map = new google.maps.Map(document.getElementById("map"), myOptions); 
       var marker=new google.maps.Marker({ 
       position: latlng, 
       map: map 
       }); 
        marker.setMap(map); 

     document.getElementById("lat").innerHtml=latlng.lat(); 
     document.getElementById("lng").innerHTML=latlng.lng(); 

} 
    function getAddress() 
    { 

    var address = document.getElementById("address").value; 

    var latlng; 
    geocoder.geocode({'address': address},function(results, status) 
    { 

     if (status == google.maps.GeocoderStatus.OK) 
     { 
     latlng = results[0].geometry.location; 
     document.getElementById("lat").innerHTML= latlng.lat(); 
     document.getElementById("lng").innerHTML= latlng.lng(); 
     map.setCenter(results[0].geometry.location); 

     var markers = new google.maps.Marker({ 
      map: map, 
      position: results[0].geometry.location 
     }); 
     markers.setMap(Map); 



    } 

     else { 
     alert("Geocode was not successful for the following reason: " + status); 
      } 

    }); 
    } 
</script> 

<body onload="initialize();"> 


<form action="./vf" onsubmit="getAddress();return false;" method="post"> 
<table> 
<tr> 
     <td> <input id="address" type="text" size="60" name="address"/></td> 
     <td> <input type="submit" value="Search!" /> </td> 
</tr> 
<tr> 
     <td>Latitude 
     <input type="text" name="latitude" id="lat" size="66" /></td> 
</tr> 
<tr> 
     <td>Longitude 
       <input type="text" name="long" id="lng" size="66" /></td> 
</tr> 

     <!--Latitude:<span name="latitude" id="lat"></span> <br /><br /> 
     Longitude: <span name="long" id="lng"></span>--> 

</table> 
</form> 
<div align="center" id="map" style="width: 100%;top: 5%; height: 95%"><br/> 
</div> 
</body> 
</html> 

듣고는 할 수있는 하나의 그림 밖으로

+0

가능한 중복 (HTTP 내 코드하십시오이다 /stackoverflow.com/questions/8118160/googlemap-javascript) – ManseUK

답변

0

변경 코드를

document.getElementById("lat").innerHTML= latlng.lat(); 
document.getElementById("lng").innerHTML= latlng.lng(); 

document.getElementById("lat").value= latlng.lat(); 
document.getElementById("lng").value= latlng.lng(); 
[GoogleMap으로 자바 스크립트]의
+0

고맙습니다. 고맙습니다. 고맙습니다. –

+0

예, 나의 문제는 innerHTML을 값으로 변경하여 해결했습니다. –

+0

안녕하세요, 저를 도와 주셔서 고맙습니다.하지만이 코드에는 1 개의 오류가 더 있습니다. 내 마커는 모든 newrequest에 대해 일정하게 머물러 있습니다. 내지도에서 8 개의 마커를 볼 수 있습니다. 위의 프로그램에서 구문을 유지할 곳은 –