How to show an alert on JavaScript , when GoogleMaps/StreetView it's not available for a location?

103 views Asked by At

I'm using GoogleMaps/StreetView option for my web page . But when StreetView it's not available for some locations it just goes grey .

I want to show an alert with JavaScript when the StreetView for that location it's not available .

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




});

When no data is available it doesnt show any alert .

1

There are 1 answers

0
MrUpsidown On

You can use the getPanoramaByLocation method of the StreetViewService class.

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