2011-05-02 21 views
5

Tamam, kullanıcı ülkeyi seçer, daha sonra otomatik tamamlama widget'ları ile yaşadıkları bölge, şehir ve alanı seçerler. Seçtikleri değerler bir adreste birleştirilir. Google Maps API arayıp adresini işaretleyen bir Haritası'nı görüntülemek için kullanılması gerektiğini ... ... Firebug bu durum alıyorum Maalesef bu çalışmıyor:Seçilen adresi gösteren bir google haritaları görüntüleme

yakalanmamış istisna: [istisna. nsresult: "0x80004005 (N: .. " 0x80004005 (NS_ERROR_FAILURE) [nsIDOMViewCSS.getComputedStyle] Bileşeni döndürülen hata kodu" S_ERROR_FAILURE)" konum: "JS çerçeve :: http://maps.gstatic.com/intl/en_us/mapfiles/api-3/4/11a/main.js :: Xk :: hat 55" veriler: no]

İşte

benim kod:

bu 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); 
    } 
}); 
ile bir komut dosyası etiketi

Peki neler oluyor?

cevap

22

Harita nesnesini oluşturduğunuzda, bir jQuery nesnesi verirsiniz, ancak bir DOM nesnesi dışında. DOM nesnesinin kendisini deneyin.

Bazı seçenekler, yakınlaştırma düzeyi ve harita türü ekledim.

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

Mükemmel:

İşte son kodudur! Tam istediğim şekilde çalıştım! Teşekkür ederim :) – Kassem

+0

Ben document.getElementById ('addressMap') $ ('div # addressMap') eşdeğerdir izlenim altında idi. Açıkça değil. Bana yardım ettiğin için teşekkürler. –

+1

@AdamWaite 'document.getElementById()' bir DOM nesnesini döndürür, '$()' jQuery nesnesini döndürür. –

İlgili konular