phplocationwebservice-clientlocation-providerwebservicehost

Search Nearby Location by Coordinate?


i am trying to create a web service for our mobile developers.

I have database of coordinates of locations. How do I return the result of nearby coordinates given a coordinate? Lets say within a radius of 100 miles.

Any idea?


Solution

    1. Create an empty array.
    2. For each location, test whether the location is say within a radius of 100 miles of your coordinate. If it is, add that location to the array.
    3. Convert the array to a format applicable for the webservice, e. g. SOAP or JSON.
    4. Output the converted array

    The distance in meters between to points with coordinates (lat1|lng1) and (lat2|lng2) can be calculated using

          arccos(sin(lat1)sin(lat2)+cos(lat1)cos(lat2)cos(lng1-lng2))
    -----------------------------------------------------------------------
    sqrt((cos(0.5(lat1+lat2))/6378137)^2 + (sin(0.5(lat1+lat2))/6356752)^2)
    

    The numerator calculates the respective distance on a sphere with radius 1. The denominator adjusts for the radii of the earth across the minor and major axis.