Ruchira
Ruchira

Reputation: 962

Google Street View Image API - check whether street view exists or not

I'm using Google streetview Image API in order to get the street view of a particular address. When the address is not found, I would like to show my own placeholder image instead of the image returned by Google. Does someone know how to do that? As I feel, the only way I can distinguish between a valid image and invalid image is, checking the image size (If the image size is less than like 4KB, it's most probably the Google default image for street view not found). I'm not really proud of myself for that invention so that's why I'm searching on a more reliable and nice way.

I'm happy to use any other API as well as long as it does the job.

Thanks.

Upvotes: 0

Views: 867

Answers (2)

Horse
Horse

Reputation: 3063

Do a check on the StreetViewService to see if there is coverage, then do whatever street view image API calls you need to do within there.

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

sv.getPanoramaByLocation(myLatlng, 50, function(data, status) {
    if (status == 'OK') {
        console.log('SV');
    }
    else {
        console.log('no SV');
    }
});

Upvotes: 3

user3710680
user3710680

Reputation: 1

Without further information such as code snippet or at least programming language, it will be difficult to provide a concrete example.

Assuming that you are using PHP, you can use PHP's getimagesize() function to get the size of the image. Simply replace the URL in the example with your Street View request URL.

HTTP Header

You can also check the HTTP Header for response size. Check the Content-Length field. For example in Java

new DataOutputStream(response.getOutputStream()).size();

Upvotes: -1

Related Questions