SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Find the closest location near your address

    Can anyone give me a hand with this please? I've been looking for something that I can work with, but not having all that much success.

    So it's pretty much just a form in PHP that you would type your address, and a distance you're willing to travel, then the script would query the DB for the addresses there using google maps API, and turn out with a list of results closest to your address using the distance the end user defined.

    Similar to this: http://web.sa.mapquest.com/timhortons/?tempset=search

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess you're able to get the latitude and longitude for a location?

    You can use this query to query the database:
    Code MySQL:
    SELECT * , 6371.04 * acos( cos( pi( ) /2 - radians( 90 - Latitude) )
    * cos( pi( ) /2 - radians( 90 - '$latitude' ) ) * cos( radians(
    Longitude) - radians( '$longitude' ) ) + sin( pi( ) /2 - radians( 90
    - Latitude) ) * sin( pi( ) /2 - radians( 90 - '$latitude' ) ) ) AS
    Distance
    FROM MyLocations
    WHERE ( 6371.04 * acos( cos( pi( ) /2 - radians( 90 - Latitude) ) *
    cos( pi( ) /2 - radians( 90 - '$latitude' ) ) * cos( radians(
    Longitude) - radians( '$longitude' ) ) + sin( pi( ) /2 - radians( 90
    - Latitude) ) * sin( pi( ) /2 - radians( 90 - '$latitude' ) ) ) <1 )
    GROUP BY one_id HAVING dist < '$radius'
    ORDER BY Distance
    LIMIT 0 , $numberOfResults

    Where:
    • MyLocations = The table with your locations
      Fields:
      • id
      • Name
      • Latitude
      • Longitude
    • $longitude = The longitude
    • $latitude = The latitude
    • $radius = The radius in kilometers
    • $numberOfResults = The maximum number of results you want
    FOR SALE: 1 set of morals, never used, will sell cheap

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Off Topic:

    Wow - bookmarked this one.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •