been reading up on this in stack overflow and other places, and tried to put together some coding to do the job I need. I will have a zip code (for test purposes it is fixed at 28752) and I want the page to give me locations within 50 miles of the zip code. Most of what I read is way over my head, but I cobbled together the following, and to the best of my limited knowledge it should work (giving me a list of records within the parameters), but it isn't.
First of all I set up the parameters using the following...
$zipcode="28752";
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$zipcode."&sensor=false";
$details=file_get_contents($url);
$result = json_decode($details,true);
$lat=$result['results'][0]['geometry']['location']['lat'];
$lng=$result['results'][0]['geometry']['location']['lng'];
$range = 50;
// Find Max - Min Lat / Long for Radius and zero point and query
$lat_range = $range/69.172;
$lon_range = abs($range/(cos($latitude) * 69.172));
$min_lat = number_format($lat - $lat_range, "4", ".", "");
$max_lat = number_format($lat + $lat_range, "4", ".", "");
$min_lon = number_format($lng - $lon_range, "4", ".", "");
$max_lon = number_format($lng + $lon_range, "4", ".", "");
Then I set up the sql query as follows...
$LA1_RESULTS = "-1";
if (isset($min_lat)) {
$LA1_RESULTS = $min_lat;
}
$LO1_RESULTS = "-1";
if (isset($min_long)) {
$LO1_RESULTS = $min_long;
}
$LO2_RESULTS = "-1";
if (isset($max_long)) {
$LO2_RESULTS = $max_long;
}
$LA2_RESULTS = "-1";
if (isset($max_lat)) {
$LA2_RESULTS = $max_lat;
}
mysql_select_db($database_XMASTREE, $XMASTREE);
$query_RESULTS = sprintf("SELECT * FROM zip_code WHERE zip_code.latitude BETWEEN %s AND %s AND zip_code.longitude BETWEEN %s AND %s", GetSQLValueString($LA1_RESULTS, "int"),GetSQLValueString($LA2_RESULTS, "int"),GetSQLValueString($LO1_RESULTS, "int"),GetSQLValueString($LO2_RESULTS, "int"));
$RESULTS = mysql_query($query_RESULTS, $XMASTREE) or die(mysql_error());
$row_RESULTS = mysql_fetch_assoc($RESULTS);
$totalRows_RESULTS = mysql_num_rows($RESULTS);
The output can be seen at http://signature-online.net/xmastrees/zipsearch.php where it gives the lat and long variables correctly. I have set up the lat and long in the database as decimal (6 decimal places).
I am the original "know just enough to be dangerous"! Can anyone figure out what I have done wrong?