How can I tell if Google's Streetview Image API Returns “Sorry, we have no imagery here” (ie. NULL) Result?

后端 未结 8 672
清酒与你
清酒与你 2020-12-03 07:38

The Google Street View Image API lets you embed a static (non-interactive) Street View panorama or thumbnail into your web page, without the use of JavaScript.

Reque

8条回答
  •  没有蜡笔的小新
    2020-12-03 08:16

    Consider using StreetViewService and StreetViewStatus objects in Google Maps: https://developers.google.com/maps/documentation/javascript/streetview#StreetViewService

    Essentially what you'll have to do is create a StreetViewService object that will try to find a panorama based on location, using the getPanoramaByLocation(latlng:LatLng, radius:number, callback:function(StreetViewPanoramaData, StreetViewStatus)) method.

    In the callback function, have a conditional argument that will check for the data availability if (status == google.maps.StreetViewStatus.OK). Based on the boolean return, execute the desired actions. The first link I provided got a great example of the use of these methods.

    Note: I also notice you've got locations based on addresses. This can be simply converted to LatLng using the Geocoding Service ( https://developers.google.com/maps/documentation/javascript/geocoding )

提交回复
热议问题