如何检查Google街景视图是否可用并显示消息? [英] How to check if Google Street View available and display message?

查看:255
本文介绍了如何检查Google街景视图是否可用并显示消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我传递lat和lng变量并在div中显示google sreet视图。问题是,当StreetView不可用时,则不显示任何内容。我想检查是否有给定经纬度和街景的街景并显示一条消息。这里是我的代码:

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());

有什么想法吗?

Any ideas?

推荐答案

在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:

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
    }
});

这篇关于如何检查Google街景视图是否可用并显示消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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