【发布时间】:2012-02-16 11:53:10
【问题描述】:
我知道关于 SO 的这个问题有很多很多的答案,但我无法找到适用于这种情况的答案。我正在异步调用 Google 服务并需要返回结果:
function getCustomPanorama(pano,zoom,tileX,tileY) {
client.getPanoramaById(pano, function(result, status) {
return {
location: result.location,
links: result.links,
copyright: result.copyright+' BUT GREY',
tiles: {
tileSize: result.tiles.tileSize,
worldSize: result.tiles.worldSize,
centerHeading: result.tiles.centerHeading,
getTileUrl: getCustomPanoramaTileUrl
}
};
});
}
我明白上面是错误的并且不会返回,并且认为我需要使用回调,但我不明白在哪里。请注意,我无法更改传递给 getCustomPanorama 的内容。感谢所有帮助。
更新:完整代码:
var panorama;
var client;
$(document).ready(function() {
var panoramaOptions = {
position: new google.maps.LatLng(51.52241608253253, -0.10488510131835938),
panoProvider: getCustomPanorama
};
client = new google.maps.StreetViewService();
panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
});
function getCustomPanorama(pano,zoom,tileX,tileY) {
client.getPanoramaById(pano, function(result, status) {
return {
location: result.location,
links: result.links,
copyright: result.copyright+' BUT GREY',
tiles: {
tileSize: result.tiles.tileSize,
worldSize: result.tiles.worldSize,
centerHeading: result.tiles.centerHeading,
getTileUrl: getCustomPanoramaTileUrl
}
};
});
}
更新 2:
建议肯定是我正在尝试做一些不可能的事情,所以尝试另一种方法,包括预先缓存 getPanoramaByID() 响应。
【问题讨论】:
标签: javascript asynchronous google-maps-api-3 callback