2013-11-09 27 views
-1

下面是我的地理編碼的JavaScript。我的地圖不會出現,我似乎無法找到我的錯誤。請指教。地理編碼沒有出現

我試圖顯示實際位置的「真實」值。 API在Google開發人員網站上正確生成。

<script> 
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.get.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); 
     } 
    }); 
    } 

</script> 

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=drawing&sensor=true"></script> 
+0

請提供足夠的代碼/ HTML到重現這個問題(或者是一個jsfiddle或者是一個顯示問題的地圖的鏈接)。 – geocodezip

+0

修復你的javascript錯誤。 – geocodezip

回答

1

你是否在任何地方運行initialize()?如果沒有,你的地圖不會顯示出來。

2

您有至少3個JavaScript錯誤,這將導致問題:

  1. JavaScript是大小寫敏感的:

    • 中心是不一樣的中心
    • 經緯度是不一樣的LatLng
  2. 「Center:latl」後面缺少一個逗號NG 「中在MapOptions

  3. 這是不正確的(額外的」。獲得「):

    變種地址= document.get.getElementById( '地址')值;

應該是:

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

而作爲Jimmie Johansson觀察,沒有調用初始化(或爲此事codeAddress)

working example