Hello,
Google Maps charge for making API calls - so it is obviously prudent to minimise the number of API calls that are made. (I appreciate that Google Maps has a free monthly quota but we exceed that so end up paying -- in any case, making 3 times as many calls as needed exhausts the free quota more quickly so we start paying sooner and also we end up paying 3 times what is necessary...)
At this time, I have only checked the code for Calendar/Events, but I suspect that everywhere else that has maps will have the same or a similar issue...
"eventSidebar.phtml" (for example) has the following three calls to generate the map:
{{if $address || $event->map( 500, 500 )}}
<div data-ips-hook="mapWrapper" class='ipsBox ipsPull'>
{{if $event->map( 500, 500 )}}
<div data-ips-hook="map" class='cEvents__sidebarMap'>
{$event->map( 500, 500 )|raw}
</div>
{{endif}}
{{if $event->venue || $address}}
<div data-ips-hook="venueWrapper" class='i-padding_3'>
{{if $event->venue}}
<div data-ips-hook="venue" class=''>
<h3 class='ipsMinorTitle'>
<strong>{lang="event_venue_name"}</strong>
</h3>
{lang="calendar_venue_{$event->venue()->id}" escape="true"}
</div>
{{endif}}
{{if $address}}
<div data-ips-hook="address">{$address|raw}</div>
{{endif}}
</div>
{{endif}}
</div>
{{endif}}
(OK - so, I admit that in practice it probably reduces to only 2 calls because if a map can be generated then there is almost certainly an address so the first call does not actually occur 😉)
$event->map() calls GeoLocation::buildFromJson which returns a new instance and rendering of the map so (as far as I can see) the map is rendered 2 or 3 times when once would do ...
Although it would not be the solution that I would want, if you at least hold the rendered map inside the $event object and return that help map on each call to $event ->map() then the unnecessary calls to Google Maps would be avoided. Note: this is not the same as caching the rendered map to disk so it should not breach the Google Maps terms and conditions.
I believe the above describes the bug... The following is an additional point that would potentially solve a problem for me...
Because of the cost of thousands of lookups to the Google Maps API what I actually need is some way for me to control the number of actual lookups and also return alternative data. For example, if someone is quickly browsing many events then there could be many map renderings in a short period of time - so one thing that I would want to do is rate limit map rendering - either on an individual member basis or perhaps on a server wide basis (most likely the former, but that could depend upon Executive Committee decisions). If I were to implement rate limiting then once the limit has been hit I would want to display an alternative image with a snippet of text to explain what has happened and why.
I did start to look at the above because I was hoping to find a way to use a "data-ips-hook" to achieve what I needed - but this falls down for two (at least) main reasons:
- {{if $address || $event->map( 500, 500 )}} occurs before the hook so the Google Maps API call could have occurred before I have any chance to take action
- There is no way to choose when to render a map or not... Of course, we can set which groups can see maps so we can block (non-paying) guests from seeing a map so that only (paying) members get to see maps - but that is not dynamic - a particular member can either always see maps or never see maps and we cannot choose on a lookup by lookup basis as part of rate limiting.
So what I would really like - what I think could provide a solution to my problem - is to have a listener/extension for maps. We would need at least two functions:
- "proceedWithApiCall()" - returns bool - would be called from Invision GeoLocation and Map functions to decide whether to proceed and make API calls. Our software would return "true" for proceed or "false" to not make any API calls.
- "alternativeImage()" - returns an alternative image to display - perhaps a static outline of the country or a globe or something and probably with a message explaining that rate limiting has occurred - for example.
Thanks very much,
John
Recommended Comments
There are no comments to display.