我正在为我的网页使用Google地图/街景选项。但是当街景在某些位置不可用时,它只是变灰 .
我想在 JavaScript 的街景不可用时显示警报。
function initialize(imei) {
$.ajax(
{
dataType: "json",
url: "index.php/application/getcordinatesgoogle/" + imei,
}).done(function( response ) {
var cafe = new google.maps.LatLng(response.y,response.x);
var panoramaOptions = {
position: cafe,
pov: {
heading: 270,
pitch: 0
},
visible: true
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), panoramaOptions);
});
当没有可用数据时,它不会显示任何警报。
您可以使用
街景服务类的getPanoramaByLocation
方法。
panoramaService = new google.maps.StreetViewService();
runPanoramaService(new google.maps.LatLng(0, 0), 1000);
function runPanoramaService(location, radius) {
panoramaService.getPanoramaByLocation(location,
radius,
function (streetViewPanoramaData, streetViewStatus) {
if (streetViewStatus == "OK") {
alertPanoAvailable(true);
} else {
alertPanoAvailable(false);
}
});
}
function alertPanoAvailable(val) {
// Do what you want here val will be either true or false
console.log('panorama available?', val);
}