Near Latitide&Longitide; for given postcode - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Near Latitide&Longitide; for given postcode (/showthread.php?tid=52267) |
Near Latitide&Longitide; for given postcode - El Forum - 06-04-2012 [eluser]veledrom[/eluser] Hi, Apologised if not relevant to CI. I am using http://codeigniter.com/wiki/Google_Maps_API_V3_Library for my purposes. Let me explain what I need with an example. I have a postcode NW1 5LR and its LATITUDE:51.546069024064 LONGITUDE:-0.235949008191785 coming from user entry. I also have many other postcodes and their Latitide&Longitide; values in database. What formula should I use to get only those postcodes which are in 1 mil away maximum? Thanks Near Latitide&Longitide; for given postcode - El Forum - 06-04-2012 [eluser]Learn CodeIgniter[/eluser] You have a whole table full of places with latitude and longitude’s associated with them. Just replace the $lat and $lon with the center point you want to find distances from. You can also change the distance => 1 to a number you want to search from. This will limit your results to all results that are greater then 1 miles from the starting point. You can change the distance for what you need. Code: $sql = Near Latitide&Longitide; for given postcode - El Forum - 06-04-2012 [eluser]veledrom[/eluser] LOVELY. This works perfectly fine. One more question: What if I want distance in KMs instead of MILEs? Code: SELECT postcode, ((ACOS(SIN('51.546069024064' * PI() / 180) * SIN(latitude * PI() / 180) + Near Latitide&Longitide; for given postcode - El Forum - 06-04-2012 [eluser]veledrom[/eluser] I don't understand how this query knows that value 1 in HAVING clause represents MILE? Is it really 1 MILE or 1 KM? Near Latitide&Longitide; for given postcode - El Forum - 06-04-2012 [eluser]veledrom[/eluser] This is in KMs. Code: SELECT |