How to check if Google Street View available and display message?

后端 未结 3 1392
刺人心
刺人心 2020-12-01 05:46

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 c

3条回答
  •  爱一瞬间的悲伤
    2020-12-01 06:19

    You may want to check out the following reference:

    • Google Maps API Documentation: Street View Client Querying

    Determining whether a road supports Street View by visual inspection of the GStreetviewOverlay is not often feasible, or desirable from a user's perspective. For that reason, the API provides a service which programmatically requests and retrieves Street View data. This service is facilitated through use of the GStreetviewClient object.

    Basically you can use the getNearestPanoramaLatLng() method of the GStreetviewClient class, which will return you a GLatLng of the nearest point where street view is available. You can then use the distanceFrom() method to check if the nearest street view point is within a certain threshold from your source point.

    Here is a full example, which I believe should be self explanatory:

    
     
     
         
        Google Maps API - Street View Availability 
         
       
       
         
       
    
    

提交回复
热议问题