如何检查谷歌街景是否可用并显示消息?
我正在传递 lat 和 lng 变量并在 div 中显示 google 街道视图。问题是,当街景不可用时,就不会显示任何内容。我想检查是否有给定纬度和经度的街景并显示一条消息。这是我的代码:
var myPano = new GStreetviewPanorama(document.getElementById("street2"), panoOpts);
var location = new GLatLng(lat,lng)
myPano.setLocationAndPOV(location);
也许我应该使用类似的东西: Event.addListener(myPano, "error", errorMessage());
有什么想法吗?
I am passing lat and lng variables and display google sreet view in a div. The problem is that when the StreetView is unavilable then nothing is displayed. I would like to check if there is a streetview for a given lat and lng and display a message. Here is my code:
var myPano = new GStreetviewPanorama(document.getElementById("street2"), panoOpts);
var location = new GLatLng(lat,lng)
myPano.setLocationAndPOV(location);
Maybe I should use something like: Event.addListener(myPano, "error", errorMessage());
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 v3 中,这发生了一些变化。请查看 http://code.google.com/ 上的文档apis/maps/documentation/javascript/reference.html#StreetViewService
更新后的代码是:
In v3 this has changed a bit. Check out the documentation at http://code.google.com/apis/maps/documentation/javascript/reference.html#StreetViewService
The updated code is:
您可能需要查看以下参考资料:
基本上,您可以使用
getNearestPanoramaLatLng()
GStreetviewClient
方法a> 类,它将返回一个GLatLng
可以查看街景的最近点的。然后,您可以使用distanceFrom()
方法检查最近的街道视图点是否距源点在特定阈值内。这是一个完整的示例,我认为应该是不言自明的:
You may want to check out the following reference:
Basically you can use the
getNearestPanoramaLatLng()
method of theGStreetviewClient
class, which will return you aGLatLng
of the nearest point where street view is available. You can then use thedistanceFrom()
method to check if the nearest street view point is within a certain threshold from your source point.Here is a full example, which I believe should be self explanatory:
Google Maps JavaScript API v3.25+ 更新:
在 v3.25(当前发布版本)和 v3.26(当前实验版本)中,
getPanoramaByLocation()
仍然可用,但 不再记录。@arthur-clemens 接受的答案仍然有效,但如果您想要更好的兼容性,请使用
getPanorama()
和StreetViewLocationRequest
代替:在
source
中省略source
code>StreetViewLocationRequest 如果您不希望全景搜索仅限于室外。Update for Google Maps JavaScript API v3.25+:
In v3.25 (current release version) and v3.26 (current experimental version),
getPanoramaByLocation()
is still available but not documented anymore.@arthur-clemens's accepted answer still works, but use
getPanorama()
with aStreetViewLocationRequest
instead if you want better compatibility:Omit
source
in theStreetViewLocationRequest
if you do not want the panorama search to be limited to outdoor ones.