AdrianHolmes
AdrianHolmes

Reputation: 71

Google Static Map API - Exceed usage limit detection

According to the documentation requesting a map from Google (via the Static Map API) when you have exceeded the usage limit displays an 'error' image. This is okay I guess but what I really want to do is detect the error so I can log something meaningful and alert the team.

Does anybody know if anything is returned in the RequestHeader to confirm this error. I can see from the documentation there is an 'X-Staticmap-API-Warning' key but its unclear if this is populated in this case.

Of course we'll be monitoring the usage via the Developer Console, but it would be good if we didn't have to rely on our customers reporting a problem should we see a spike.

Thanks in advance...

Upvotes: 2

Views: 335

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117354

The HTTP-status of the image will be 403 when you see the error-image.

But that wouldn't help you much, because an <img/> doesn't have a property which gives you the HTTP-status.

Possible solution(works when the static map does have a size different to 100x100 ):

The error-image does have a size of 100x100, observe the onload-event and when the naturalWidth and naturalHeight is 100, do something:

<img src="staticmapurl"     
     onload="if(this.naturalWidth==this.naturalHeight==100){/*do something*/}"
/>

But note: there is also a quota for users, when google returns the error-image it must not be related to the quota of your project

Upvotes: 2

Related Questions