Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type for "locations" and I need to have "users" log in and be able to pick a location that is within a certain distance from them.

I have added some spots to the profile using update_contact_methods() to get an address etc, and the location custom post type I am using the Custom-Metaboxes-and-Fields-for-WordPress to add specific fields for address information etc.

I am simply not sure of how to achieve what I need to and am hoping for some input.

I need to get it working quickly so I am more concerned with at least a proof-of-concept approach then the most performant. My initial thought was to use Google Maps API distance matrix, https://developers.google.com/maps/documentation/javascript/distancematrix but I am not sure if that is a good way to go...

A thought was to have a page that is clickable once user is logged in, that would, upon navigating to it, would need to iterate through each "location" custom post and compare its address as destination and the logged in users address (pulled from profile) as origin, and discard the post if > (greater than) x hours. Does that make sense?

I would really appreciate any help you all may have to give, I have confused myself into a corner.

Thank you!

share|improve this question
    
Would be easier to help if you post your code please. –  Brad Dalton May 4 at 5:52

1 Answer 1

Several good links that might get you going:

If you use the Google Maps API to return a lat and long position, and store those in the database in a custom field, then you can use the Haversine formula to calculate distances and you won't need google maps for that anymore (google lookups make things slow). You might also store some meta info on the locations, so you can rule out groups of locations (countries, states, provinces etc).

The links have php excerpts you can use.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.