Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Lat/Lng individual? #1

Closed
distantnative opened this issue Nov 26, 2014 · 10 comments
Closed

Get Lat/Lng individual? #1

distantnative opened this issue Nov 26, 2014 · 10 comments
Assignees

Comments

@distantnative
Copy link

Any way to get the latitude or longitude individually?
Would be a great way, if one could do $page->location()->lat()

@rutger1140
Copy link
Owner

Good idea. I'm not sure how I could make your suggestion work though.

I currently split the string on a comma in my template. Originally I wanted to use two fields in Kirby, but I had some issues with that so I chose to use one field.

@distantnative
Copy link
Author

True... thought about custom field methods, but that's not really an ideal way and would require to add another file to a different folder. Not worth it, I think.

Maybe just include in your README
Latitude: $page->location()->split(',')[0]
Longitude: $page->location()->split(',')[1]

For even more beginners convenience ;)

@rutger1140
Copy link
Owner

I've found a 'workaround' for this.
With the use of field methods you can create your own helpers.

  • Inside /site/plugins/ create a file named methods.php
  • In this file create your own helpers like this:
<?php
field::$methods['lat'] = function($field) {
  $parts = explode(',',$field->value);
  return $parts[0];
};
field::$methods['lng'] = function($field) {
  $parts = explode(',',$field->value);
  return $parts[1];
};

Now in your template you should be able to do:
$page->location()->lat() and $page->location()->lng()

I will see about including it in the plugin somehow.

@rutger1140
Copy link
Owner

lol, we posted about the same fix on the same time I see 👍

@distantnative
Copy link
Author

Exactly - but as that file has to be in the plugins folder, I think it is better to not include it into your plugin. Would make the install more complicated for that lil help

@rutger1140 rutger1140 self-assigned this Nov 27, 2014
@timgauthier
Copy link

include a plugin and a field in the distro?

@rutger1140
Copy link
Owner

@timgauthier The explanation above you should help to get you going. The 'field part' of the geolocation field is merely a string split, nothing too fancy.
Because they have to reside in separate folders @distantnative and I decided to leave it like it is. Maybe when Kirby supports the two combined into 1 package I'll reconsider.

@ghost
Copy link

ghost commented May 23, 2015

The map does not appear in my template. Using Kirby 2.1.0. I have followed all the steps and do not to make this worked. Only appear the two number (Lat & Lng)

@tasinttttttt
Copy link

Hey @juangiga the plugin only stores the geolocation data. It's up to you to generate a map (using mapbox or google maps for example) and add the geolocation.

You can look at the geolocation.js file in the assets/js plugin folder for an example of how to generate a google map with the marker.

@rutger1140
Copy link
Owner

Hi @juangiga, please create a new issue if your problem still persists.

Repository owner locked and limited conversation to collaborators May 25, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants