[pmwiki-users] How to add a geolocalisation function to APE ?

Petko Yotov 5ko at 5ko.fr
Sun Nov 1 08:58:01 PST 2020

After a discussion with Benjamin, I've implemented this in APE version 
20201029, and at the same time I've updated the Leaflet.js library to 
its latest version.

If you upgrade, all files need to be replaced, except if you have a 
custom pub/ape/ape-local.js file.

A new button is added below the "+/-" zoom controls. When a visitor 
clicks on it, the program will request Geolocation permissions and if 
the user accepts it, the map will be zoomed in or out and centered over 
the user's position, and a round dark red dashed circle marker will be 

Notes: my previous comments about reliability and precision still apply. 
Also: the Geolocation feature only works in a secure context (both 
website and Ape on a HTTPS protocol).


If you upgrade :  http://www.pmwiki.org/Upgrades

On 28/10/2020 18:53, Petko Yotov wrote:
> On 28/10/2020 15:14, Benjamin Grassineau wrote:
>> Do you think it would be possible to add a geolocalisation function to
>> APE ? Or to create an independant function wich could be added by a
>> markup ? It would be yet very useful for my website.
> Do you mean having an Openstreetmap automatically centered, or insert
> a pin, over the visitor's location? (1)
> Or do you want an editor to be able to add a pin while editing the
> source text of the wiki page? (2)
> Some hosting providers (e.g. OVH) have an ip2location module installed
> on their servers and you can get an approximate latitude and longitude
> in PHP from the $_SERVER array. It shouldn't be complicated to create
> a custom markup, or a GUI button, that inserts the coordinates in an
> APE definition list.
> While this would be easy and automatic, there are 2 difficulties --
> 1. The coordinates may be incorrect or missing for some users -- for
> example my home location doesn't show, but others do.
> 2. If you change hosting providers it may not work on the new service.
>> In fact, I've tried to do this with JavaScript but I did not arrived !
>> It's true that I am not very cumfortable with this language. I tried
>> to use the |getCurrentPosition()| method.
> This would be the way to go for modern browsers, but it is done in 2
> steps -- you first need to request location permissions from the
> browser, and then if the visitor grants them you can request the
> geographic coordinates. So depending on what you want to achieve (1)
> or (2) above, it needs to be done differently. (1) needs to be
> implemented in APE, (2) can be independent.
> Here too it is not 100% reliable: the user may refuse to grant the
> permissions, or the coordinates may be imprecise or incorrect, but
> this as good as it gets.
> Petko

More information about the pmwiki-users mailing list