bartleby Posted March 18, 2011 Share Posted March 18, 2011 I have a company that has been developing my site, and we are stuck on the best way to accomplish a key part of the site. FYI, I am very laman when it comes to code. Based on my address and a mile radius which I will define, my customers will come to my site and enter their address. The system needs to be able take the entered address and my address and confirm that it is within the radius that I set. From what I understand, geocode the two addresses, measure the distance between and make sure it is within the defined radius. Right now all we are finding is zip code radius search api's which are too broad. We need to be fairly accurate. In case it helps, this is for a delivery service and I will only serve a small radius to begin with, but the radius will increase as needed. I appreciate any help or suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/231040-geocoding-radius-search-api/ Share on other sites More sharing options...
thehippy Posted March 20, 2011 Share Posted March 20, 2011 Convert locations to longitude and latitude like Google Maps does, hell use their API to do so. Determine a suitable radius for your delivery zone by defining it in long and lat, compare with user's co-ordinates if they fit in your zone. Just a note for you, not everyone here is from the same country, mentioning which country you're in and therefore which postal code system you're using would help. Quote Link to comment https://forums.phpfreaks.com/topic/231040-geocoding-radius-search-api/#findComment-1190069 Share on other sites More sharing options...
Zane Posted March 21, 2011 Share Posted March 21, 2011 Once you get this formula down, you could make about any kind of geographical type program. Just combine it with creativity. Here's how to get this formula. First, note that it's very easy to get a distance between two points on a sphere if you know the angle of the arc between them: just multiply it by the radius. So we're going to concentrate on finding this angle. We're going to use the fact that the dot product of two vectors is equal to the product of their lengths, times the cosine of the angle between them. At the same time, we can compute a dot product coordinate by coordinate. Let the vectors a and b be the vectors from the center of the earth to each of our points. Using spherical coordinates, we can write them down explicitly: a = (r cos(Long1)cos(Lat1), r sin(Long1)cos(Lat1), r sin(Lat1)) b = (r cos(Long2)cos(Lat2), r sin(Long2)cos(Lat2), r sin(Lat2)) We take their dot product and get r^2 (cos(Long1)cos(Long2)cos(Lat1)cos(Lat2) + sin(Long1)sin(Long2)cos(Lat1)cos(Lat2) + sin(Lat1)sin(Lat2)) By the other formula for dot product, this is r^2 times the cosine of the angle between them. So cancel the r^2, and take the inverse cosine. You'll get the formula above (if you simplify some terms). The Earth is irregular In fact the earth is not a sphere. It is generally an "oblate spheroid", meaning that it is somewhat flattened at the poles. But the true shape of the Earth is actually irregular, and it is therefore impossible to determine by formula the exact distance between two points. Various approximations of the shape of the earth, called reference ellipsoids, are used in other, more complex formulas that come closer to the actual distance. The spherical solution given here is pretty close for many purposes though. Read more: http://wiki.answers.com/Q/What_is_the_formula_for_distance_using_latitude_and_longitude#ixzz1HBrGjHKf Quote Link to comment https://forums.phpfreaks.com/topic/231040-geocoding-radius-search-api/#findComment-1190108 Share on other sites More sharing options...
bartleby Posted March 21, 2011 Author Share Posted March 21, 2011 Thanks for the replies. I will make sure I sit down with the developers to discuss this. I appreciate your help. Quote Link to comment https://forums.phpfreaks.com/topic/231040-geocoding-radius-search-api/#findComment-1190126 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.