Geo Sorting Post

Can you use a plugin? I just released not long ago http://geomywp.com it basically does what you want. If you want to do it yourself so this is how I did it:
The plugin adds address custom fields (as meta boxes) to your post type. When post is being saved the address being converted to lat/long using google API and the data being saved in a custom table. This way you create a database table for your posts with lat/long.
When a user want to search your site Using the search form he can enter any address in the input field and choose radius value from drop down menu. The address again , being converted to lat/long and using custom SQL query you can check the user’s address against each lat/long in the custom database’s table. Then you can output posts within the given radius and ordered them by the distance from the address.

Leave a Comment