2011-05-02 2 views
5

사용자가 국가를 선택하면 자동 완성 위젯을 통해 선택한 지역, 도시 및 지역을 선택하게됩니다. 선택한 값은 주소로 연결됩니다 Google지도 API를 호출하고 주소를 표시하는지도를 표시하는 데 사용해야합니다. 불행히도이 작업이 작동하지 않습니다 ... 방화범 입력이 예외가 발생합니다.선택한 주소를 보여주는 Google지도 표시하기

잡히지 않은 예외 : [Exception. .. "구성 요소가 실패한 코드를 반환했습니다 : 0x80004005 (NS_ERROR_FAILURE) [nsIDOMViewCSS.getComputedStyle]" nsresult : "0x80004005 (N S_ERROR_FAILURE) "위치 :"JS 프레임 :: http://maps.gstatic.com/intl/en_us/mapfiles/api-3/4/11a/main.js :: XK : 라인 55 "데이터 : NO]

다음

내 코드 없습니다 :

src="http://maps.google.com/maps/api/js?sensor=false"

var address = selectedArea + ', ' + selectedCity + ', ' + selectedDistrict + ', Lebanon'; 

var geocoder = new google.maps.Geocoder(); 
geocoder.geocode({ 'address': address }, function (results, status) { 
    if (status == google.maps.GeocoderStatus.OK) { 
     var map = new google.maps.Map($("#addressMap")); 
     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); 
    } 
}); 
있는 스크립트 태그

무슨 일 이니?

답변

22

지도 개체를 만들 때 jQuery 개체를 제공하지만 DOM 개체는 제외합니다. DOM 객체 자체를 사용해보십시오.

일부 옵션, 확대/축소 수준 및지도 유형을 추가했습니다.

var address = selectedArea + ', ' + selectedCity + ', ' + selectedDistrict + ', Lebanon'; 

var geocoder = new google.maps.Geocoder(); 
geocoder.geocode({ 'address': address }, function (results, status) { 
    if (status == google.maps.GeocoderStatus.OK) { 
     var mapOptions = { zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP }; 
     var map = new google.maps.Map(document.getElementById('addressMap'), mapOptions); 
     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

완벽한 :

여기에 최종 코드입니다! 내가 원하는 방식으로 정확하게 일했다! 감사합니다 :) – Kassem

+0

나는 document.getElementById ('addressMap')가 $ ('div # addressMap')와 동일하다는 인상하에있었습니다. 분명히. 도와 주셔서 감사합니다. –

+1

@AdamWaite'document.getElementById()'는 DOM 객체를 반환하고,'$()'는 jQuery 객체를 반환합니다. –

관련 문제