Search code examples
javascriptmysqlmapsregiongeocode

Google Maps Search addresses by custom Region


I have a database of addresses and I want to be able to have a user drop a pinpoint on the map and define a region based on driving distance around that point. I was wondering if there was a way to search my database by that user defined region.


Solution

  • For the International System that uses Kilometers, replace a part of the script with this one:

    6371 * acos( cos( radians(LATITUDE1) ) * cos( radians( LATITUDE2 ) ) * cos( radians( LONGITUDE1 ) - radians(LONGITUDE2) ) + sin( radians(LATITUDE1) ) * sin( radians( lat ) ) ) AS DISTANCE
    

    Source: http://www.codecodex.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe#MySQL