我正在尝试将谷歌地图结果映射到缓存。问题在于数据变量在第一次搜索时始终未定义。它只会在第二次搜索后才有结果(使用相同的术语)。任何人都可以检查什么问题?
if (!(me.data = me.googleSearchCache[ location ])) {
var geocoderRequest = {
address: location
}
geocoder.geocode(geocoderRequest, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
me.googleSearchCache[ location ] = $.map(results, function(loc) {
return {
value : loc.formatted_address,
//bounds : loc.geometry.bounds,
lat : loc.geometry.location.lat(),
lng : loc.geometry.location.lng()
};
});
}
});
}
data = me.googleSearchCache[ location ];
debug(data);