The Problem

Today a member had a bit of an unusual request, they are using GeoDirectory to run a local festival and they are listing things like accommodation for it. The request was to show the distance in each listing to the main event so users have a clear understanding of how far it will be to the event from each listing. I do something very similar on one of my own sites that is for one location, i list the distance to the airport and the distance to the main town, i have until now just had users enter this distance manually, this is often wrong and i have to correct it.

The Solution

This seemed like the perfect time to create a new custom field, lets call it “Distance to”. The code is below but there are two ways to use this field:
#1 We could just add the field and let the user enter GPS coordinates, it might be for example a “closest airport” field, the user could then enter the GPS info for the closest airport to them.
#2 In this users case he just needs to show the distance to one place and without the user really needing to even know about the field, so when he is adding the custom field he would set the field as a “admin only” field so it is not shown to the user on the frontend and they can’t change it, and then set the “default value” to the GPS coordinates needed and all listings will then show the info needed.

The Code

3 thoughts on “Distance to custom field

  1. having do have users add latitude and longitude is something that kills this whole system and makes geodirectory kind of worthless for my project

    • Hi William,

      GPS info is automatically filled in when you move the map or map marker or set the address on the map, you can even hide the GPS info boxes with a setting in the backend so the user never has to see it.

      Stiofan

  2. Good to know users don’t have put the GPS co ordinates manually. More work we put on the user more chances of them not doing it right.

Leave a Reply

Your email address will not be published. Required fields are marked *

Share This