• August 22, 2014, 10:33:39 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

beermapping.com - We find the beer. You drink the beer.

Recent Reviews:   90.0: World of Beer - Reston |   98.3: Lawson's Finest Liquids |   100.0: Taste of Tops  

Author Topic: Proximity Search  (Read 5808 times)

beerinator

  • admin
  • bmp: 27
  • Offline Offline
  • Posts: 3943
  • Reviews: 126
  • January 19, 2007
    Location: Chicago, IL
    • View Profile
    • View Review List
    • View Reviews on a Map
    • beermapping.com
Proximity Search
« on: February 16, 2007, 10:28:58 AM »

Want to plan a pubcrawl, but you don't know the city you're planning to crawl?

Want to find the closest beer store to stop at after leaving the next brewpub you plan to visit?

Well, possibly, a new feature that I'm working on will help out with that!

Currently, you can view the search page by city, state, or zip.  But now I have added three new links under each location.



As you can see, you now have an option to click "1 mile", "5 miles" or "10 miles".  Each of these does about what you would expect.  Which is return all locations within that distance (note: this is not traveling distance, but a direct line radius distance - as the crow flies).

The fact that I got this to work, means that eventually I will set it up so there will be a link on the results page that will actually map out all locations that are returned as a result.

Please let me know what you think or if you find this useful!

Note: the current page is horribly ugly (edit: I have redirected the page to a prettier page - you can disregard this "note").  It simply grabs the correct locations and puts them on a plain white page with very little text formatting at all.  I will work on the "prettyness" of this page when I get a break (not today unless I start procrastinating on my other stuff :( )
« Last Edit: February 16, 2007, 11:36:40 AM by beerinator »
Logged
    beerinator

beerinator

  • admin
  • bmp: 27
  • Offline Offline
  • Posts: 3943
  • Reviews: 126
  • January 19, 2007
    Location: Chicago, IL
    • View Profile
    • View Review List
    • View Reviews on a Map
    • beermapping.com
Re: Proximity Search
« Reply #1 on: February 16, 2007, 10:53:11 AM »

By the way, just in case someone out there is working on their own map stuff (I know kp does some), here is the code for the distance algorithm.  I found it online and I barely know what the math does, but I had to rework it to fit with the beermapping stuff.

Code: [Select]
<?php $filterSize $dist// miles

// Get boundaries of filter window
$maxLat $lat + ( $filterSize 69 ); // 69 miles per degree of latitude
$minLat $lat - ( $filterSize 69 );
$maxLon $lng + ( $filterSize / ( 69.172 cos$lat 0.0174533 ) ) );
$minLon $lng - ( $filterSize / ( 69.172 cos$lat 0.0174533 ) ) );

// Simplify terms to speed query
$originLatRadCos cos$lat 0.0174533 );
$originLatRadSin sin$lat 0.0174533 );
$originLonRad    $lng 0.0174533;

// SQL for filtered records
$baseSql "SELECT *, 3963 * acos( ( $originLatRadSin * sin( lat *
0.0174533 ) ) + ( 
$originLatRadCos * cos( lat * 0.0174533 ) * cos(
( lng * 0.0174533 ) - 
$originLonRad ) ) ) AS distanceFromOrigin
FROM locations WHERE lat <= 
$maxLat AND lat >= $minLat AND
lng <= 
$maxLon AND lng >= $minLon";

$sql "SELECT * FROM ($baseSql) AS filteredTable WHERE
distanceFromOrigin <= 
$filterSize ORDER BY name";
?>

Basically, a variable in the query string ($dist) is used to filter the locations in the database that have a latitude and longitude that are within a certain value range depending on the original location's lat/long.  Most of the heavy math goes into the SQL query that actually goes out and builds a table with the locations that fit the criteria.  Enjoy!   :cheers:
« Last Edit: February 16, 2007, 03:59:04 PM by beerinator »
Logged
    beerinator

kp

  • POI Subscriber
  • bmp: 10
  • Offline Offline
  • Posts: 580
  • Reviews: 19
  • February 14, 2007
    Location: Woodstock, GA
  • I have nothing to say
    • View Profile
    • View Review List
    • View Reviews on a Map
    • Atlanta Beer
Re: Proximity Search
« Reply #2 on: February 16, 2007, 11:21:04 AM »

You answered my question before I could even ask it.

This would also be useful with the marker clustering to automatically cluster markers within x miles of each other at a y zoom level.
Logged

beerinator

  • admin
  • bmp: 27
  • Offline Offline
  • Posts: 3943
  • Reviews: 126
  • January 19, 2007
    Location: Chicago, IL
    • View Profile
    • View Review List
    • View Reviews on a Map
    • beermapping.com
Re: Proximity Search
« Reply #3 on: February 16, 2007, 02:43:50 PM »

You answered my question before I could even ask it.

This would also be useful with the marker clustering to automatically cluster markers within x miles of each other at a y zoom level.

I think this would be a good tool for the city maps that beermapping has.  At the moment I am "approving" towns that go along with each city map.  Giving each City map a 50 or so mile radius would make that part of the mapping process much easier.  I could also make it so the radius could be expanded or contracted if a user wanted to see more or less depending on the center of the search.

I'm not exactly sure what formula they are using for the clustering, but it does have something to do with setting the bounds of the map depending on the lat/long.  It's probably much simpler math since the lat/long wouldn't need to be converted to miles for the map to be able to cluster points. 

But simply having these options will open up a lot of different options for future beer maps.
Logged
    beerinator

hopalong

  • betamapper
  • bmp: 0
  • Offline Offline
  • Posts: 72
  • Reviews: 0
  • January 20, 2007
    Location: Durham, NC
  • beer here now!
    • View Profile
Re: Proximity Search
« Reply #4 on: February 18, 2007, 10:19:03 AM »

What about kilometers??   :D

Also, I'm wondering when the features will be added to actually show a route map with directions.  Enter starting location (brewery, pub, ...), ending location, and perhaps radius or a list of places to include, specify walking / driving / public transportation, press enter, and ... Presto Chango! ... you get a map, a route, times between locations, recommended beers, food pairings, proper glassware and serving temperature suggestions, ...  (ok, getting carried away here)   :D :D
Logged

beerinator

  • admin
  • bmp: 27
  • Offline Offline
  • Posts: 3943
  • Reviews: 126
  • January 19, 2007
    Location: Chicago, IL
    • View Profile
    • View Review List
    • View Reviews on a Map
    • beermapping.com
Re: Proximity Search
« Reply #5 on: February 18, 2007, 10:29:15 AM »

What about kilometers??   :D

Also, I'm wondering when the features will be added to actually show a route map with directions.  Enter starting location (brewery, pub, ...), ending location, and perhaps radius or a list of places to include, specify walking / driving / public transportation, press enter, and ... Presto Chango! ... you get a map, a route, times between locations, recommended beers, food pairings, proper glassware and serving temperature suggestions, ...  (ok, getting carried away here)   :D :D
It is likely that I will never be able to add direction functionality directly into beermapping's maps.  Google is not releasing that information as far as I know.  And I wouldn't begin to tell you how hard or costly it would be for me to figure out how to get directional information to work inside beermapping's maps.

Find me a few million dollars and I'll look into it.
Logged
    beerinator

kp

  • POI Subscriber
  • bmp: 10
  • Offline Offline
  • Posts: 580
  • Reviews: 19
  • February 14, 2007
    Location: Woodstock, GA
  • I have nothing to say
    • View Profile
    • View Review List
    • View Reviews on a Map
    • Atlanta Beer
Re: Proximity Search
« Reply #6 on: February 18, 2007, 10:45:14 AM »

What about kilometers??   :D

Also, I'm wondering when the features will be added to actually show a route map with directions.  Enter starting location (brewery, pub, ...), ending location, and perhaps radius or a list of places to include, specify walking / driving / public transportation, press enter, and ... Presto Chango! ... you get a map, a route, times between locations, recommended beers, food pairings, proper glassware and serving temperature suggestions, ...  (ok, getting carried away here)   :D :D
It is likely that I will never be able to add direction functionality directly into beermapping's maps.  Google is not releasing that information as far as I know.  And I wouldn't begin to tell you how hard or costly it would be for me to figure out how to get directional information to work inside beermapping's maps.

Find me a few million dollars and I'll look into it.
Google is not releasing it yet, but their verbiage kinda sounded like they might in the future. I'd like an API that would just give me travel time between two locations.
The direction I'm going with http://AtlantaBeer.com/ is to try and put together beer tours with direction information between each of the stops. I've kinda got this going by having a manual preplanned itinerary and then linking to Google's page for the actual routing. The Carolina set is the most complete example right now (since it was the last big trip that I made and I'm doing these for myself as I take trips).
Logged

beerinator

  • admin
  • bmp: 27
  • Offline Offline
  • Posts: 3943
  • Reviews: 126
  • January 19, 2007
    Location: Chicago, IL
    • View Profile
    • View Review List
    • View Reviews on a Map
    • beermapping.com
Re: Proximity Search
« Reply #7 on: February 18, 2007, 01:49:38 PM »

By the way, I have capped the "proximity search" at 75 miles (this only really applies to anyone who might have been playing around with the url string).  I don't want someone entering in 1,000,000 miles and ending up with a list of every single location in the database on that page.

The distance calculation also works for decimal numbers as well, so for locations that are in highly metropolitan areas, you might want to do a .5 or .75 distance radius.

I believe, that the direction I am planning to take with this is to give users two options.  One would be to find a location on either the map or through the search and give them the ability to search for locations within a certain radius.  The results would be able to be shown in a map or printed in a fairly clean results page.

The other option will be for the user to be able to enter a new location that will not be stored in the database.  This new location will act as the center of the radius and it can be a location of any type (hotel, house, street corner...) as long as it is a mappable address.  So you could enter in the address of the hotel that you are planning to stay at in San Diego and that location will act as the center of your search radius.  Hopefully this should prove useful for travelers.
Logged
    beerinator

beerinator

  • admin
  • bmp: 27
  • Offline Offline
  • Posts: 3943
  • Reviews: 126
  • January 19, 2007
    Location: Chicago, IL
    • View Profile
    • View Review List
    • View Reviews on a Map
    • beermapping.com
Re: Proximity Search
« Reply #8 on: February 18, 2007, 04:23:56 PM »

Ok, this feature is still in "live beta" simply because I suck really bad at testing.

The mapping functions are active at this point.  There is a link on the proximity page that will allow you to "map" the locations that are listed there.  Here is an example, using The Map Room at a one mile radius;



When you click that link, you will get a "custom map" that has the same radius as the search/proxy page.  The radius that was chosen is drawn in a circle around the center point.  This helps to show a user exactly the distance between the center and the outer edge of the circle.

Here again is an example using The Map Room at a one mile radius (click the example image to jump to the actual map);



Hopefully someone will find this useful.  I'm pretty sure that whenever I set it up so you can choose a custom center point it will become even more useful.


Logged
    beerinator

beerinator

  • admin
  • bmp: 27
  • Offline Offline
  • Posts: 3943
  • Reviews: 126
  • January 19, 2007
    Location: Chicago, IL
    • View Profile
    • View Review List
    • View Reviews on a Map
    • beermapping.com
Re: Proximity Search
« Reply #9 on: February 18, 2007, 07:24:43 PM »

I think I have most of the bugs worked out on these maps at the moment. 

Internet Explorer 7 (and possibly IE6) was broken for a while, but it is fixed at the moment.  The "bookmarking options" were broken for a while, but they are fixed at the moment.  Otherwise I think I have tested most everything (I'm sure I neglected something...) and it all seems to be working.
Logged
    beerinator

kp

  • POI Subscriber
  • bmp: 10
  • Offline Offline
  • Posts: 580
  • Reviews: 19
  • February 14, 2007
    Location: Woodstock, GA
  • I have nothing to say
    • View Profile
    • View Review List
    • View Reviews on a Map
    • Atlanta Beer
Re: Proximity Search
« Reply #10 on: July 10, 2007, 10:27:54 PM »

Code: [Select]
// SQL for filtered records
$baseSql = "SELECT *, 3963 * acos( ( $originLatRadSin * sin( lat *
0.0174533 ) ) + ( $originLatRadCos * cos( lat * 0.0174533 ) * cos(
( lng * 0.0174533 ) - $originLonRad ) ) ) AS distanceFromOrigin
FROM locations WHERE lat <= $maxLat AND lat >= $minLat AND
lng <= $maxLon AND lng >= $minLon";

$sql = "SELECT * FROM ($baseSql) AS filteredTable WHERE
distanceFromOrigin <= $filterSize ORDER BY name";

So what version of what DB allows you to do those funky selects where you can build a filtered set of rows as a temp table on the fly?
Logged

beerinator

  • admin
  • bmp: 27
  • Offline Offline
  • Posts: 3943
  • Reviews: 126
  • January 19, 2007
    Location: Chicago, IL
    • View Profile
    • View Review List
    • View Reviews on a Map
    • beermapping.com
Re: Proximity Search
« Reply #11 on: July 10, 2007, 10:52:51 PM »


So what version of what DB allows you to do those funky selects where you can build a filtered set of rows as a temp table on the fly?

MySQL 5.0.27 is what that code is running on.
Logged
    beerinator
 

Page created in 0.113 seconds with 25 queries.