You need to get points between the two coordinates - maybe using the Haversine formula and then collect the zipcodes for the points along the line.
Retrieve zipcodes within Lat Long Coordinates
-
07-07-2023 - |
Question
I have 2 points containing Lattitude and Longitude Coordinates. I'd like to figure out how to find the zipcodes within this set of Points. I have a query which provides me with a set of zipcodes based on a central lattitude and longitude point extending X miles in radius, but that isn't precisely what I am looking for. What I am looking for is to extract the zipcodes within two points.
So, for example:
Coordinate A = 28.37,-81.5568 (Orlando, Florida)
Coordinate B = 25.6132,-80.3474 (Miami, Florida)
Here is my query to extract all locations from my database based on a central point (In this case I am using Orlando, FL:
$sql="SELECT zip_code_id, (
3959 * ACOS (
COS ( RADIANS(28.37) )
* COS( RADIANS( lat ) )
* COS( RADIANS( lon ) - RADIANS(-81.5568) )
+ SIN ( RADIANS(28.37) )
* SIN( RADIANS( lat )
))) AS distance FROM zip_code HAVING distance < 30 ORDER BY distance LIMIT 0 , 20;";
What I am trying to determine is the zipcodes within Orlando to Miami based on these two points.
Thanks!
La solution