2013-05-31 39 views
1

我不得不承認,我使用Google Maps API做了一點。大量的複製和粘貼以及基本的編輯。除非街道視圖圖像不可用,否則此代碼運行得非常好。什麼是最簡單的方式來檢測沒有圖像和隱藏pano div?或者反過來,顯示它是否有一個形象:我可以修改此代碼來檢測Google Maps API中是否有街景圖像可用?

function googleMap() { 

     var geocoder = new google.maps.Geocoder(); 

      if (geocoder) { 
       alert('<?php echo $phoneDirectory->Address; ?>'); 
      geocoder.geocode({ 'address': '<?php echo $phoneDirectory->Address; ?>' }, function (results, status) { 
       if (status == google.maps.GeocoderStatus.OK) { 


        var googleLat = results[0].geometry.location.lat(); 
        var googleLong = results[0].geometry.location.lng(); 
        //alert(googleLat + ", " + googleLong); 


       var fenway = new google.maps.LatLng(googleLat,googleLong); 
       var mapOptions = { 
        center: fenway, 
        zoom: 14, 
        mapTypeId: google.maps.MapTypeId.ROADMAP 
       }; 

       var map = new google.maps.Map(
        document.getElementById('map_canvas'), mapOptions); 
        var panoramaOptions = { 
         position: fenway, 
         pov: { 
         heading: 0, 
         pitch: 0 
        } 
       }; 

       var panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'),panoramaOptions); 
       map.setStreetView(panorama); 

       // **** ADDED TO GET WORKING!!! ***** 
       var client = new google.maps.StreetViewService(); 
       client.getPanoramaByLocation(fenway, 50, function(result, status) { 
        if (status == "ZERO_RESULTS") { 

         // Hide street view div 
         $('#pano').css("display", "none"); 


        } 

       });  

       googleMapLoaded = true; 


       } 
       else { 
        alert('No results found: ' + status); 
       } 
      }); 
      }   

} 

回答

1

Check this

如果附近沒有全景的結果是ZERO_RESULTS

+0

設法得到它的工作,感謝您的督促。我曾經看過這個函數/代碼。我只是沒有意識到我可以將它添加到我現有的代碼中,而不是編輯或替換我的代碼。我現在更新了我的源代碼片段。 –

+0

+1對你的問題問題,因爲你採取了額外的步驟,並粘貼了一個工作的例子。 – alkis

相關問題