144 posts
  • 6 Years of Membership
  • Affiliate Level 2
  • Collector Level 4
  • Exclusive Author
+1 more
joomlaianer
says

I`ve a question.

i made a business directory with custom post types. is it possible to let users search after the category or taxonomies and add a radius search?

for example.

i search in category a with a radius search of 10 miles.

hope u understand what i`m talking about :)

144 posts
  • 6 Years of Membership
  • Affiliate Level 2
  • Collector Level 4
  • Exclusive Author
+1 more
joomlaianer
says

no solutions ?

737 posts
  • Affiliate Level 7
  • Author Level 8
  • Collector Level 3
  • Top Monthly Author
+9 more
mordauk
says

It is possible, though it’s rather difficult. You would have to store the locations in post meta fields, and then look for ones that are near the search when you search for a radius. The difficult part is that you have to find a way to calculate distances from each place’s location that is stored in the meta field.

240 posts
  • Affiliate Level 1
  • Author Level 5
  • Collector Level 1
  • Top Monthly Author
+4 more
phpdude
says

Basically, what you need to do is when a custom post is added/updated it needs to Geocode via Google the Lat and Long from the postcode/zip code etc and store these in separate fields.

Then you add a text input to search, the input for this is Geocoded via Google too to get the lat and long of the location, then parse this through a fairly simple SQL which calculates the distance between the the search lat and long and each of the rows lat and long, then only show ones which are within X miles.

Geocode like so:
$address = 'London, UK';
$lines = explode("\n",file_get_contents('http://maps.google.com/maps/geo?q='.urlencode($address).'&output=csv&key='.$google_map_key));
list($x,$x,$lat,$long) = explode(',', $lines[0]);
SQL like so:
$miles = 5; // Show only results within 5 miles
mysql_query("SELECT *, truncate((degrees(acos( sin(radians(`lat`)) * sin( radians('".$lat."')) + cos(radians(`lat`)) * cos( radians('".$lat."')) * cos( radians(`long` - '".$long."') ) ) ) * 69.09),1) as distance FROM `postcodes` WHERE truncate((degrees(acos( sin(radians(`lat`)) * sin( radians('".$lat."')) + cos(radians(`lat`)) * cos( radians('".$lat."')) * cos( radians(`long` - '".$long."') ) ) ) * 69.09),1) <= ".$miles." ORDER BY `distance` ASC");

SQL is just off the top of my head, so hopefully it will work, if not it will point you in the right direction.

144 posts
  • 6 Years of Membership
  • Affiliate Level 2
  • Collector Level 4
  • Exclusive Author
+1 more
joomlaianer
says

what would it cost to develop such a plugin ? unfournetly i cant write php :)

186 posts
  • 3 Years of Membership
  • Philippines
nicole_anderson
says

Hello joomlaianer!

If you really prefer custom plugin, then go to my profile and contact me and lets go from there. I’d be waiting on your mail then.

Regards, Nicole

2 posts
  • 3 Years of Membership
  • Author Level 3
  • Exclusive Author
  • United Kingdom
kodefoundry
says

Having the Lng/Lat coordinates stored in the postmeta table makes it difficult (if not impossible) to do sorting and advanced distance queries. Ideally, you should have a separate table with appropriate data types for columns (double/float). I’ve done quite a bit with GiS systems in the past so if you are still looking to get this developed, feel free to send me a message via by profile page.

Kevin

1 post
  • 2 Years of Membership
  • Collector Level 2
  • United Kingdom
rszecsodi
says

I have just found this plugin it works for me on my premiumpress install.

http://www.web-directory-service.com/universalwp/wp-radius-search/
by
by
by
by
by
by