如何判断 Google 的街景图像 API 是否返回“抱歉,我们这里没有图像"?(即.NULL)结果? [英] How can I tell if Google's Streetview Image API Returns "Sorry, we have no imagery here" (ie. NULL) Result?

查看:30
本文介绍了如何判断 Google 的街景图像 API 是否返回“抱歉,我们这里没有图像"?(即.NULL)结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 街景图像 API 可让您嵌入静态(非交互式)街景全景图或缩略图显示在您的网页中,无需使用 JavaScript.

The Google Street View Image API lets you embed a static (non-interactive) Street View panorama or thumbnail into your web page, without the use of JavaScript.

请求网址:http://maps.googleapis.com/maps/api/streetview?parameters

+问题+

如果我给它一个没有街景的地址,它会返回一张图片,上面写着抱歉,我们这里没有图片".

If I give it an address for which it doesn't have a Streetview, it returns an image that says, "Sorry, we have no imagery here".

基于当前的 API,我无法检测它是否找到街景.任何人都有解决这个问题的技巧或建议?

Based on the current API, I have no way of detecting if it found a Streetview or not. Anyone have a hack or suggestion for figuring this out?

+示例+

正确的街景:http://maps.googleapis.com/maps/api/streetview?size=300x300&sensor=false&location=100+Highland+Ave+Baltimore,+MD+21224

抱歉街景:http://maps.googleapis.com/maps/api/streetview?size=300x300&sensor=false&location=1600+Pennsylvania+Ave,+Washington,+DC+20500

推荐答案

考虑在 Google 地图中使用 StreetViewService 和 StreetViewStatus 对象:https://developers.google.com/maps/documentation/javascript/streetview#StreetViewService

Consider using StreetViewService and StreetViewStatus objects in Google Maps: https://developers.google.com/maps/documentation/javascript/streetview#StreetViewService

本质上,您需要做的是创建一个 StreetViewService 对象,该对象将尝试根据位置查找全景图,使用 getPanoramaByLocation(latlng:LatLng, radius:number, callback:function(StreetViewPanoramaData, StreetViewStatus)) 方法.

Essentially what you'll have to do is create a StreetViewService object that will try to find a panorama based on location, using the getPanoramaByLocation(latlng:LatLng, radius:number, callback:function(StreetViewPanoramaData, StreetViewStatus)) method.

在回调函数中,有一个条件参数将检查数据可用性if (status == google.maps.StreetViewStatus.OK).根据布尔值返回,执行所需的操作.我提供的第一个链接是使用这些方法的一个很好的例子.

In the callback function, have a conditional argument that will check for the data availability if (status == google.maps.StreetViewStatus.OK). Based on the boolean return, execute the desired actions. The first link I provided got a great example of the use of these methods.

注意:我还注意到您有基于地址的位置.这可以使用地理编码服务( https://developers.google.com/maps/documentation/javascript/geocoding )

Note: I also notice you've got locations based on addresses. This can be simply converted to LatLng using the Geocoding Service ( https://developers.google.com/maps/documentation/javascript/geocoding )

这篇关于如何判断 Google 的街景图像 API 是否返回“抱歉,我们这里没有图像"?(即.NULL)结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆