Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detecting "we have no imagery" of google maps street view static images

I'm generating street view static images like so:

https://maps.googleapis.com/maps/api/streetview?size=1080x400&location=%s&fov=90&heading=235&pitch=0&key=%s

If you visit that link you see an image that says, "Sorry, we have no imagery for this..."

Is there any way to detect this "sorry" state so that I can fall back to another image?

like image 584
tester Avatar asked Oct 20 '11 17:10

tester


People also ask

Why does Google Maps say sorry we have no imagery here?

MyGeotab uses Google's API, in some areas, some map-tiles are missing for certain zoom levels (usually very high zoom levels). This can also happen if Google Maps is down.

Why is my Google Maps Street View not working?

Make sure you have a clear GPS signal, then re-capture your image. Unable to process location information: Re-capture the Street View. File is corrupt: Re-upload the file. If it doesn't get published again, then re-capture the Street View.

Is Google Maps static or dynamic?

The Google Maps Platform static web APIs let you embed a Google Maps image on your web page without requiring JavaScript or any dynamic page loading. The APIs create an image based on URL parameters sent through a standard HTTP request and allow you to display the result on your web page.

Is Google Maps static free?

The Maps Static API uses a pay-as-you-go pricing model. Requests for the Maps Static API are billed under the SKU for Static Maps. Along with the overall Google Terms of Use, there are usage limits specific to the Maps Static API. Manage your costs and usage with tools available in the Google Cloud Console.


4 Answers

One quick solution would be to load the image file using xmlrpc and check that its md5sum is 30234b543d5438e0a0614bf07f1ebd25, or that its size is 1717 bytes (it's unlikely that another image can have exactly the same size), but that's not very robust since I have seen Google change the position of the text in the image. Though it's a very good start for a prototype.

You could go for image processing instead. Note that it's still not perfectly robust since Google could decide to change the looks of the image anytime. You'll have to decide whether it's worth it.

Anyway, here is how I would do it using jQuery:

  • load the image and open a 2D context for direct pxiel access (see this question for how to do it)
  • analyse the image:
    • sample groups of 2×2 pixels at random locations; I recommend at least 30 groups
    • a group of 2×2 pixels is good if all the pixels have the same value and their R/G/B values do not differ by more than 10% (ie. they're grey)
    • count the ratio of good pixel groups in the image
  • if there are more than 70% good pixel groups, then we are pretty sure this is the “no imagery” version: replace it with another image of your choice.

The reason I do not recommend testing directly for an RGB value is because JPEG decompression may have slightly different behaviours on different browsers.

like image 157
sam hocevar Avatar answered Oct 23 '22 07:10

sam hocevar


this situation is already build in in the 3.0 version due the boolean test status === streetviewStatus.Ok, here is a snippet from my situation solving

if (status === google.maps.StreetViewStatus.OK) {
            var img = document.createElement("IMG");
            img.src = 'http://maps.googleapis.com/maps/api/streetview?size=160x205&location='+ lat +','+ lng  +'&sensor=false&key=AIzaSyC_OXsfB8-03ZXcslwOiN9EXSLZgwRy94s';
            var oldImg = document.getElementById('streetViewImage');
            document.getElementById('streetViewContainerShow').replaceChild(img, streetViewImage);
        } else {
            var img = document.createElement("IMG");
            img.src = '../../images/ProfilnoProfilPicture.jpg';
            img.height = 205;
            img.width = 160;
            var oldImg = document.getElementById('streetViewImage');
            document.getElementById('streetViewContainerShow').replaceChild(img, streetViewImage);
        }
like image 24
thegrunt Avatar answered Oct 23 '22 09:10

thegrunt


As of 2016, you can use the new Street View Image Metadata API.

Now you just need the status field to know if a panorama is found.


Example requests:

https://maps.googleapis.com/maps/api/streetview/metadata?size=600x300&location=78.648401,14.194336&fov=90&heading=235&pitch=10&key=YOUR_API_KEY

{
   "status" : "ZERO_RESULTS"
}


https://maps.googleapis.com/maps/api/streetview/metadata?size=600x300&location=eiffel%20tower,%20paris,%20france&heading=-45&pitch=42&fov=110&key=YOUR_API_KEY

{
   ...
   "status" : "OK"
}
like image 28
Thomas Orlita Avatar answered Oct 23 '22 09:10

Thomas Orlita


You can use the getPanoramaByLocation function (see http://code.google.com/apis/maps/documentation/javascript/services.html#StreetViewService).

try something like this:

function handleMapClick()
{
 var ll= new google.maps.LatLng(latitude,longitude);
 sv.getPanoramaByLocation(ll, 50, processSVData);
}

function processSVData(data, status) {
 if (status==google.maps.StreetViewStatus.ZERO_RESULTS)
 {
   <DO SOMETHING>
 }
}
like image 26
mikescandy Avatar answered Oct 23 '22 08:10

mikescandy