uelski
uelski

Reputation: 13

Google Maps Street View "No Imagery" with status OK

I have been working with the Google Street View Image API and have an issue when api responds with "we have no imagery". I implemented a few solutions I found from previous posts, mostly from detecting "we have no imagery" of google maps street view static images. Here is my code:

var address = thisItem.addr + "," + thisItem.city + "," + thisItem.state + " " + thisItem.zip;

    var url = "https://maps.googleapis.com/maps/api/streetview?size=500x500&location=" + address + "&heading=&pitch=&key=";

    var itemLat = parseFloat(thisItem.lat);
    var itemLng = parseFloat(thisItem.lng);

    var sv = new google.maps.StreetViewService();


    sv.getPanorama({location: {lat: itemLat, lng: itemLng}, radius: 1}, processSVData);

    function processSVData(data, status) {
      if (status === google.maps.StreetViewStatus.OK) {
        console.log('status ok');
      } else {
        console.log('status not ok')
      }
    }

I am going to plug the url into an img src if there is a street view.

Because I am using the address and not lat lng in the url call, and lat lng in the getPanorama, when an image returns with "no imagery found" the StreetViewStatus is still OK so I am not able to set a stock image. I also changed to use the lat lng in the url and then an image will always show up even if the status is not OK. Any suggestions?

Upvotes: 1

Views: 1433

Answers (1)

Teyam
Teyam

Reputation: 8092

As discussed in Directly Accessing Street View Data

You may initiate two types of requests to the StreetViewService:

  • Request with a StreetViewPanoRequest, this returns panorama data given a reference ID which uniquely identifies the panorama. Note that these reference IDs are only stable for the lifetime of the imagery of that panorama.
  • Request with a StreetViewLocationRequest this searches for panorama data over a given area, given a passed LatLng.

So, for addresses that you used, I suggest that you should consider converting them using Geocoding Service.

Aside from that, these references might help you too

Upvotes: 2

Related Questions