possible? radius search using full text indexing of mysql?

Discussion in 'MySQL' started by jnm, Sep 28, 2006.

  1. #1
    Anyone know or have done it? Anyone know where I can learn about it if it is possible or a script to buy?
    ex. "Bills Diner" within 5 miles of zip 90210

    can you create the full text index for the zip and diner name and then add Boolean search to something like this...
    
    $query = "SELECT *.dinerTable FROM zipTable,
    	dinerTable WHERE (POW((69.1*(lon-\"$lon\")
    	*cos($lat/57.3)),\"2\") +
    	POW((69.1*(lat-\"$lat\")),\"2\")) <
    	($radius*$radius) AND zip.dinerTable = zip.zipTable";
    
    Code (markup):

    Unfortunately for me I have no clue on how to do it :( Any help would be great.
    Thanks!

    -J
     
    jnm, Sep 28, 2006 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    ccoonen, Sep 28, 2006 IP
  3. mnemtsas

    mnemtsas Super Dud

    Messages:
    497
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, quite possible. I'd do it in PHP rather than trying to select out like that though. In fact thats exactly how I did it on the locator system at http://www.comfortkeepers.com/.
     
    mnemtsas, Oct 1, 2006 IP
  4. jimjam

    jimjam Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    im working on something simular but could do with some help;

    I have two functions which work separately perfectly as two separate forms

    The first; (as no one will know what lattitude and longitude their zip code is) changes their zip code into two coordinates (longitute and latitude).

    I have a second function performs the search using lattitude and longitude to find stores that are within a certain area.

    Both work great but I can't work out how to join the two functions into one .

    Function one
    
    function getCoords($zip)
    {
    	
    	echo '<h2>stores</h2><p>you searched for '.$zip.'</p>';
    	$db_conn = db_connect(); // database connection
    
    	// turn long and lat into zipcode
        $query = "SELECT latitude, longitude
    	FROM zipcodes
    	WHERE '".$zip."' = zip";
    }
    
    PHP:
    Function two
    
         $query = "SELECT store_id, store_name, store_address, store_zipcode,
       3963 * acos(cos(radians(90-latitude ))*cos(radians(90-'".$latitude."'))+sin(radians(90-latitude ))
    	* sin(radians(90-'".$latitude."'))
    	*cos(radians(longitude- '".$longitude."')) 
    	) AS distance
    	FROM stores, zipcodes
    	WHERE stores.store_zipcode = zipcodes.zip
    	HAVING (distance < '".$area."')
    	ORDER BY distance asc";
    }
    
    PHP:
     
    jimjam, Oct 2, 2006 IP
  5. jamus

    jamus Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    jim jam, maybe you should make a separate thread. The problem is only related to a zipcode search and you may have more response post separately under its own title.
     
    jamus, Oct 3, 2006 IP