问题描述
我正在传递 lat 和 lng 变量并在 div 中显示谷歌街景视图.问题是当街景不可用时,什么都不显示.我想检查是否有给定 lat 和 lng 的街景并显示一条消息.这是我的代码:
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);
也许我应该使用类似的东西:Event.addListener(myPano, "error", errorMessage());
Maybe I should use something like: Event.addListener(myPano, "error", errorMessage());
有什么想法吗?
推荐答案
在 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
更新后的代码是:
var streetViewService = new google.maps.StreetViewService();
var STREETVIEW_MAX_DISTANCE = 100;
var latLng = new google.maps.LatLng(40.7140, -74.0062);
streetViewService.getPanoramaByLocation(latLng, STREETVIEW_MAX_DISTANCE, function (streetViewPanoramaData, status) {
if (status === google.maps.StreetViewStatus.OK) {
// ok
} else {
// no street view available in this range, or some error occurred
}
});
这篇关于如何检查谷歌街景是否可用并显示消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!