如何检查 Google 街景图像 API 是否没有返回图像?
我正在使用 Google 街景图像 API 来显示图像一个位置的。
它工作正常,但是当没有可用图片时,我会得到黑色图像而不是位置图片。有什么方法可以检查是否没有返回图像并显示另一张图像?
I am using Google Street View image API to show an image of a location.
It works fine, however when no picture is available i get a black image instead of a location picture. Is there any way I can check if no image is returned and show another image instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为没有办法检查这一点。 SV 图像 API 专为无法向页面添加太多功能的静态情况而设计。
也许您应该查看JS API 中的街景,它可以让您检测图像何时可用。
I don't think there is a way to check this. The SV image API is designed for static cases when you can't add much functionality to the page.
Maybe you should look at Street View in the JS API, which will let you detect when imagery is available.
另一种方法是加载图像,然后比较一些像素的颜色。来自谷歌的“无街景”图像总是相同的。以下是比较 2 个像素的方法:
一些潜在的问题:我发现了一些 CrossOrigin 污染的错误。另外,如果谷歌更改返回的图像,则此代码将中断。
Another way is to load the image and then compare some pixels colors. The "no streetview" image from google is always the same. Here is how you would compare 2 pixels:
Some potential issues: I've seen some errors with CrossOrigin tainting. Also, if google changes the image returned this code will break.