【问题标题】:How to show an alert on JavaScript , when GoogleMaps/StreetView it's not available for a location?当 GoogleMaps/StreetView 对某个位置不可用时,如何在 JavaScript 上显示警报?
【发布时间】:2015-06-18 07:55:41
【问题描述】:

我正在为我的网页使用 GoogleMaps/StreetView 选项。但是当街景在某些位置不可用时,它会变成灰色。

我想在该位置的 StreetView 不可用时使用 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);




});

当没有可用数据时,它不会显示任何警报。

【问题讨论】:

    标签: javascript php google-maps google-maps-api-3 google-street-view


    【解决方案1】:

    您可以使用StreetViewService 类的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);
    }
    

    【讨论】:

      猜你喜欢
      • 2015-11-07
      • 1970-01-01
      • 2011-10-22
      • 2017-05-08
      • 2011-11-17
      • 1970-01-01
      • 2014-11-14
      • 2016-04-24
      • 1970-01-01
      相关资源
      最近更新 更多