cache googlemaps geocoding results but my code is broken

xCarbon

New Member
I posted this question last night but I worded it wrong and didn't explain correctly. I am trying to cache googlemaps geocoding results for use in a firefighting mapping thing I have made and I am getting close to google's limits hence the need to cache the results. Help!The code below kinda works however it creates a new sql record each time the code runs regardless of whether the address is already in the database. It seems to only call google once then saves the data, it then loads the data from the database ok and it looks like the rest works but I just can't see where I am going wrong.. As I said it creates a new record each and everytime the code runs and I would end up with a database full of the same identical records. My brain hurts but I really need to get this working so I can continue to help fire trucks to fires. :)Oh, I am using the geocoding results on googlemaps (as permitted by the T&C) and this code is really only to get it working. I hope that makes sense and I hope someone can help... Thanks :)\[code\]<?php$jobadd = "1000 BURWOOD HWY, BURWOOD";// connect to the databaseinclude('connect-db.php');// get results from database and find needle$result = mysql_query("SELECT * FROM geocache") or die(mysql_error()); while($row = mysql_fetch_array( $result )){$needle = '' . $row['address'] . '';if (strpos($jobadd,$needle) !== false){$status = "CACHED";$latitude = '' . $row['latitude'] . '';$longitude = '' . $row['longitude'] . '';}else{$status = "GOOGLE";$address2 = "$jobadd, Victoria, Australia";define("MAPS_HOST", "maps.google.com"); $base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml"; $request_url = $base_url . "?address=" . urlencode($address2) ."&sensor=false"; $xml = new SimpleXMLElement(file_get_contents($request_url)); $latitude = $xml->result->geometry->location->lat;$longitude = $xml->result->geometry->location->lng; // save the data to the databasemysql_query("INSERT geocache SET address='$jobadd', latitude='$latitude', longitude='$longitude' ") or die(mysql_error()); }}echo $status;echo '<BR>';echo $jobadd;echo '<BR>';echo 'LAT:';echo $latitude;echo '<BR>';echo 'LON:';echo $longitude;?>\[/code\]
 
Top