Kirby Geo Plugin


#1

Hey,

for a client project I had to do all sorts of geolocation based tasks. I wanted to put the result into a plugin for quite a while and now it’s available:

https://github.com/getkirby-plugins/geo-plugin

It gives you some nice methods to work with geo points, calculate distances and run geolocation queries against the Google Geo Locator.

It also adds radius filters to all collections, which can be used to search for pages/files around a certain location.

It’s already compatible with the Kirby CLI, so if you got the CLI running you can simply install it with:

kirby plugin:install geo-plugin

I hope you like it!


#2

Nice! This opens up some new possibilities. It just gave me an idea of a panel field/tool.

In the panel on a page there can be 3 fields:

(not a blueprint, just a sketch, instead of an image)

Locate target 1: [input text]
Locate target 2: [input text]
Distance: [info] (visible if exists)

When losing focus from target1 or target2, get distance with ajax and add it to the distance part of field. All 3 fields could be saved. Then the distance field would be “cached” until next ajax fetch.

With it you would don’t need lat, long to get distances between two points.


#3

To calculate the distance between two points isn’t too performance-hungry. The real performance hog is the geo locator. But it’s still a nice idea.


#4

Nice plugin!

The only problem: why is a comma used to separate lat() and lng() values?

Eg. 46,4958286, 11,3523424 instead of 46.4958286, 11.3523424, which are the actual values present in the json file fetched from the Google APIs.

I went through the plugin to see where this was happening, but could not find anything.

I am now doing a str_replace to adjust this, but would be curious to know what is the reason behind it.


#5

There seems to be a problem when using the geo::locate() command.

I opened an issue here.

Strangely enough, using google maps’ API gives a good result back, see — https://maps.googleapis.com/maps/api/geocode/json?address=Mannheim,%20Germany

Probably google updated maps’ API?


#6

Just a hunch, but is this a localisation issue? What language/timezone is your sever? Some countries use a , instead of a . for numbering. Explains why you cant find it in the code if its being done dynamically according to locale. It’s not a comma separator, i think its actually decimal character. Just a hunch, I’ve not used other languages before.


#7

Hi,

i am currently using the plugin ( on my localhost). i want to get the distance from point A to B. point A is from the user and point B is from the database.

  1. problem is that when ever i request something (over ajax), 7/10 request returns 500 error from the plugin.
  2. when ever i use the geo class, the request takes too long to return a result.

please help :slight_smile: thanks


#8

@arphie I’m not sure I understand your issue - there seem to be too many areas where things could be going wrong, which may have nothing to do with the plugin. For instance: your problem (1) could be simply an issue with your ajax code. Similarly, the issue on point (2) could be related to your database or query code.

Would you be able to post examples of your code, so someone can try to help you troubleshoot?