How to detect if Google StreetView is available in an address/coordinates
Asked Answered
A

3

7

I'm making an app that uses the Google Street View Image API

I have no problem getting an image of the street view based on the address/coordinates

but - I want to detect if the specific address has a Street View image available (in order to show a different behavior for addresses that doesn't have it)

The only idea I got so far is to read the pixels of the returned image and detect whether this is the image the I got when there is no image available

Any other idea?

Thanks!

Award answered 5/11, 2012 at 16:33 Comment(3)
Did you ever figure this out?Cropeared
@jphager2 I ended up getting the bytes of the image received from Google Street View Image API and look at the color of the pixels in the first row - since an unavailable address would always give the same image - it worked... hacky but worksAward
Ah ok. I ended up just comparing the file size.Cropeared
C
8

Using google.maps.StreetViewService.getPanoramaByLocation( latlng, radius, callback()), you can check whether there is a streetview panorama. If there is a streetview panorama, then there must be an image of streetview.

You can refer the reference of google : https://developers.google.com/maps/documentation/javascript/reference#StreetViewService

Or refer to the example of StreetViewService : https://google-developers.appspot.com/maps/documentation/javascript/examples/streetview-service

Camail answered 26/11, 2012 at 15:55 Comment(1)
that correct - but I want to do it server side, and using the maps api won't help me that muchAward
C
2

Google has an api endpoint where you can look up the metadata for a panorama/streetview:

https://maps.googleapis.com/maps/api/streetview/metadata?key=YOUR_API_KEY&location=STRING_ADDRESS_OR_LAT_LNG_COORDINATES

You can check the status property of the response.

Successful Response

{
   "copyright" : "© 2017 Google",
   "date" : "2016-05",
   "location" : {
      "lat" : 48.85783227207914,
      "lng" : 2.295226175151347
   },
   "pano_id" : "tu510ie_z4ptBZYo2BGEJg",
   "status" : "OK"
}

Failed Response

{
   "status" : "ZERO_RESULTS"
}

@see https://developers.google.com/maps/documentation/streetview/metadata

Currish answered 7/10, 2018 at 20:18 Comment(0)
T
1
  mStreetViewPanorama.setOnStreetViewPanoramaChangeListener(streetViewPanoramaLocation -> {
                if (streetViewPanoramaLocation != null && streetViewPanoramaLocation.links != null) {
                    Toast.makeText(StreetViewActivity.this, "StreetView Camera Found", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(StreetViewActivity.this, "StreetView Camera not Found", Toast.LENGTH_SHORT).show();
                }
            });
Taconite answered 17/3, 2018 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.