Project 3 with AW/BT

Given multiple zipcodes of USA, calculate polygon to connect all points together. The results will be returned to a web service to be used by a third party software (clients)

  • How do we do that?

Each zipcode can be converted to a Geo point which will include Latitude and Longitude. Yahoo, Google, and Bing Map provide a web service that we can call to convert this value.
Now we have the geocodes, let’s sort the arrays of longitudes first. Then loop through to calculate the distance of 2 adjacent points. At the end of the array, use the 1st element as the 2nd point to calculate, so that you can close the loop. Now you’ll have all the points as a result to draw a polygon on a Google map, or Bing map.

  • Sample function to do the calculation of the 2 geo points
Pass these values to a function first before this calculation can be executed.

$lat1, $lon1, $lat2, $lon2, $unit = 'M'

$theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; }