SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    zip radius class return distance calculation also?

    We use the following: http://www.phpclasses.org/browse/package/522.html

    However, it doesnt return the distance that the zip is from the input zip code.

    It uses this calculation/query:
    $query="SELECT zipcode FROM pmd_zipdata WHERE (POW((69.1*(lon-\"$lon\")*cos($lat/57.3)),\"2\")+POW((69.1*(lat-\"$lat\")),\"2\"))<($radius*$radius) "

    Anyway to get it to return also the distance?

  2. #2
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    methinks their distance calc is incorrect (could be wrong), here's mine:

    Code:
    SQRT (((69.1*(latitude-{$from_latitude})) ^ 2) + ((53*(longitude-{$from_longitude})) ^ 2))

  3. #3
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok but do you know how you might return the distance also?

  4. #4
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by atDev View Post
    Ok but do you know how you might return the distance also?
    Sure do, you also use this in the select:

    PHP Code:
    SQRT (((69.1*(latitude-{$from_latitude})) ^ 2) + ((53*(longitude-{$from_longitude})) ^ 2)) AS \"calc\"" 
    My PHP fields are in the {}

    and as far as how far to search you add this to the where clause:

    PHP Code:
    AND SQRT (((69.1*(latitude-{$from_latitude})) ^ 2) + ((53*(longitude-{$from_longitude})) ^ 2)) <={$miles_to_use}

  5. #5
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you know how this performs on large sets of data?

  6. #6
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you know how you can easily change this between miles and kilometers?

  7. #7
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also in yours where are you suppose to enter their entered radius (from the input)?

  8. #8
    SitePoint Enthusiast Cborrow's Avatar
    Join Date
    Apr 2005
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used this to do a search from one zipcode to another (using geological locations) I had a large database filled with zipcodes as well as there city, state, lon and lat.

    zipcodes is the listing of zipcodes and there city state and other things, and the locations is a database of locations for
    business and such.

    Edit: I believe this is the US zipcode listing that I used. http://www.zip-codes.com/

    Code:
    SELECT z.zipcode, z.lon, z.lat, l.name, l.id, l.address, l.city, l.state, l.zip FROM zipcodes = z, locations = l WHERE(POW((69.1 * (z.lon - '$lon') * cos($lat / 57.3)), 2) + POW((69.1 * (z.lat - '$lat')), 2)) < ($miles * $miles) GROUP BY name


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
  •