2011-01-10 21 views
1

我想創建一個地理編碼器函數,將結果寫入其參數。將參數添加到谷歌地圖地理編碼器函數

function geoCode(latlng,div) { 
    gc.geocode({'latLng': latlng}, function (result, status) { 
    if (status == google.maps.GeocoderStatus.OK) { 
     new google.maps.Marker({ 
     position: result[0].geometry.location, 
     map: map 
     }); 
     $(div).html(result[0].formatted_address); 
    }    
    }); 

如何將div參數添加到geocoder函數?

像這樣:

gc.geocode({'latLng': latlng, writeHere: div}, function (result, status) { 
... 
$(writeHere).html(result[0].formatted_address); 
} 

但它不工作。

任何幫助,將不勝感激。

回答

0

試試這個:

function geoCode(latlng, div) { 
    var $div = jq(div); 
    gc.geocode({ 
     'latLng': latlng 
    }, function(result, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      new google.maps.Marker({ 
       position: result[0].geometry.location, 
       map: map 
      }); 
      $div.html(result[0].formatted_address); 
     } 
    }); 
} 
+0

沒有...我添加了一個參數的地理編碼功能。我想把結果寫到這個'div'中,但'gc.geocode'子函數產生這個結果,我不能把這個'div'參數加到這個函數中。 – kree 2011-01-10 11:55:26