1
我很難用下面的使用Google Maps API v3的腳本來確定範圍問題。我試圖對未知數量的記錄(從數據庫中提取)進行地理編碼,並從結果中創建一個PolyLine。代碼中有些紅寶石,但它不應該與JS的權利相關?函數調用內的JavaScript範圍問題
var trippath = new Array();
function drawHistoryPath(coordinates) {
var tripHistoryPath = new google.maps.Polyline({
map: map,
path: coordinates,
strokeColor: "#6A0606",
strokeOpacity: 1.0,
strokeWeight: 5
});
}
<% @pins.each do |ps| %>
geocoder.geocode({ 'address': '<%= escape_javascript(ps.location) %>'}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
trippath.push(results[0].geometry.location);
} else {
alert("Geocode was not successful finding <%= escape_javascript(ps.location) %> for the following reason: " + status);
}
});
<% end %>
drawHistoryPath(trippath);
當drawHistoryPath被調用,trippath不存在,但我已經證實,它正在正確填充的地理編碼器函數內。任何想法爲什麼它不尊重全球範圍?
非常多讓你成爲我的英雄 – Ryan 2010-08-25 21:45:01
哈哈謝謝!好吧,祝你好運。其中一天,我會用地理編碼器的東西寫一些我自己的代碼。 – Pointy 2010-08-25 21:51:03