如何判断Google的Streetview图像API是否返回“对不起,我们这里没有图像” (即NULL)结果? [英] How can I tell if Google's Streetview Image API Returns "Sorry, we have no imagery here" (ie. NULL) Result?
问题描述
Google街景视图图像API 可让您嵌入静态(非交互式)街景全景或缩略图到您的网页,而不使用JavaScript。
请求网址: http://maps.googleapis.com/maps/api/ streetview?parameters
+问题+
如果我给它一个地址它没有Streetview,它会返回一个图片,上面写着对不起,我们这里没有图片。
基于当前的API,我无法检测是否找到了街景视图。任何人都有一个黑客或建议,以弄清楚这一点?
+示例+
的rel = noreferrer> https://developers.google.com/maps/documentati on / javascript / streetview#StreetViewService
基本上,您需要做的是创建一个StreetViewService对象,该对象将尝试根据位置查找全景图,使用 getPanoramaByLocation(latlng:LatLng,radius:number,callback:function(StreetViewPanoramaData,StreetViewStatus))
方法。 >在回调函数中,有一个条件参数将检查数据可用性 if(status == google.maps.StreetViewStatus.OK)
。基于布尔返回,执行所需的操作。我提供的第一个链接是使用这些方法的一个很好的例子。
注意:我还注意到您有基于地址的位置。这可以使用地理编码服务简单地转换为LatLng( https://developers.google.com / maps / documentation / javascript / geocoding )
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.
Request URL: http://maps.googleapis.com/maps/api/streetview?parameters
+The Problem+
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".
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?
+Examples+
Proper Streetview: http://maps.googleapis.com/maps/api/streetview?size=300x300&sensor=false&location=100+Highland+Ave+Baltimore,+MD+21224
Sorry Streetview: http://maps.googleapis.com/maps/api/streetview?size=300x300&sensor=false&location=1600+Pennsylvania+Ave,+Washington,+DC+20500
Consider using StreetViewService and StreetViewStatus objects in Google Maps: https://developers.google.com/maps/documentation/javascript/streetview#StreetViewService
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.
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.
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的Streetview图像API是否返回“对不起,我们这里没有图像” (即NULL)结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!