2011-10-30 2 views
0

'찾기'버튼을 클릭하면 위치를 찾았지만 지오 코딩 부분에 문제가 있습니다.Google지도에서 Geolocation 지오 코딩이 발생합니다.

"myaddress"div에 내 위치 주소가 표시되어 있어야합니다. 그러나 그것은 내가 이해하지 못했다는 오류를줍니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script> 
<script type="text/javascript"> 
function initialize() { 
    var latlng = new google.maps.LatLng(0, 0); 
    var myOptions = { 
     zoom: 1, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("sbmr"), 
     myOptions); 


} 

///////////////////////////////////////////////////////////////////////////// 

var initialLocation; 
var siberia = new google.maps.LatLng(60, 105); 
var browserSupportFlag = new Boolean(); 
var myposition; 
var geocoder; 

function geocode() { 

     var myOptions = { 
     zoom: 6, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 

     var map = new google.maps.Map(document.getElementById("sbmr"), myOptions); 

    // Try W3C Geolocation (Preferred) 
    if(navigator.geolocation) { 
    browserSupportFlag = true; 
    navigator.geolocation.getCurrentPosition(function(position) { 
     initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude); 


     /////////////////PROBLEM IS WITH THIS PART/////////////////// 
     var latlng = new google.maps.LatLng(initialLocation); 
     geocoder = new google.maps.Geocoder(); 
     geocoder.geocode(latlng, function(results, status) { 
      if (status == google.maps.GeocoderStatus.OK) { 
      if (results[1]) 
      document.getElementById("myaddress").innerHTML = 'results[1].formatted_address' 
      } 
      else { 
      alert("Geocoder failed due to: " + status); 
      } 
      }); 
     ////////////////////////////////////////////////// 
     var marker = new google.maps.Marker({ 
        position: initialLocation, 
        map: map, 
        animation: google.maps.Animation.BOUNCE, 
        title:"You're here." 
        }); 

     map.setCenter(initialLocation); 

     map.setZoom(15); 

     //W3C olursa yapilanlar bitis 
    }, function() { 
     handleNoGeolocation(browserSupportFlag); 
    }); 
    } 
}//geocodefinish 
</script> 

<style type="text/css"> 
<!-- 
#sbmr { 
    position:absolute; 
    left:62px; 
    top:39px; 
    width:1098px; 
    height:649px; 
    z-index:1; 
} 
#myaddress { 
    position:absolute; 
    left:1185px; 
    top:219px; 
    width:286px; 
    height:318px; 
    z-index:2; 
} 
#apDiv1 { 
    position:absolute; 
    left:1189px; 
    top:70px; 
    width:264px; 
    height:117px; 
    z-index:3; 
} 
--> 
</style> 
</head> 

<body onload="initialize()"> 



<div id="sbmr"></div> 
<div id="myaddress"> 
<h2>My address:</h2> 
<br /> 
</div> 
<div id="apDiv1"> 
    <label> 
    <input type="submit" name="button" id="button" value="Find Me" onclick="geocode()" /> 
    </label> 
</div> 
</body> 
</html> 
+0

을 오류가 무엇입니까? –

+0

알 수없는 속성 [이 오류가 발생하는 경우] I.toSpan = function() {return new Q (this ... n (b) {return b == j와 && c || b instanceof a}} main.js (라인 16) – user552828

+0

@Vlad이 파일을 firefox에서 직접 열면 문제가 나타납니다 – user552828

답변

2

지오 코더는 문자열 주소를 LatLng 개체로 인코딩합니다. 주소가있는 객체를 전달하는 대신 latlng 객체를 전달하는 것은 잘못된 일입니다.

변경이 :이와

geocoder.geocode(latlng, function(results, status) {... 

:

UPDATE
geocoder.geocode({address: "type your address here"}, function(results, status) ... 

: 이 링크 역 지오 코딩 (위도와 경도를에서 주소를 얻기를) 할 체크 아웃 찾고 있다면 : http://code.google.com/apis/maps/documentation/javascript/services.html#ReverseGeocoding

관련 문제