【发布时间】:2010-08-25 21:27:57
【问题描述】:
我很难使用 Google Maps API v3 找出以下脚本的范围问题。我正在尝试对未知数量的记录进行地理编码(从数据库中提取)并根据结果创建折线。代码中撒了一些红宝石,但它应该与JS无关吧?
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 不存在,但我已确认它已在地理编码器函数中正确填充。知道为什么它不尊重全局范围吗?
【问题讨论】:
标签: javascript jquery ruby-on-rails google-maps