作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道这个问题在 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() 响应的方法。
最佳答案
更改 getCustomPanorama
以获取一个额外的回调参数,并传入一个函数来执行您需要对结果执行的操作:
function getCustomPanorama(pano,zoom,tileX,tileY,callback) {
client.getPanoramaById(pano, function(result, status) {
var data = {
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
}
};
callback(data); // call the function and pass in the data you would have returned
});
}
getCustomPanorama(pano,zoom,tileX,tileY,function(data) {
// do something with the results of the asynchronous call here
});
关于javascript - 从自定义 panoProvider 返回异步结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9310819/
我知道这个问题在 SO 上有很多很多答案,但我一直没能找到适用于这种情况的答案。我正在异步调用 Google 服务并需要返回结果: function getCustomPanorama(pano,zo
我是一名优秀的程序员,十分优秀!