Google Map Issues
I recently did a Google Map for PodcampOhio. I had it set up so that I would just pass in a zip code to a GClientGeocoder and map that as a point. The problem was, if you're doing a lot of these at once, it would skip some at random. I wasn't sure why it was doing this, but I also saw the zip code look up for every request as pretty inefficient anyway. So I set up a function in PHP within a CodeIgniter Controller to cache the latitude and longitude for the zip codes (it's not like they're going to change):
function cache_new_zips(){
$query = $this->db->query("SELECT ".
"DISTINCT i.zip_code ".
"from information i where i.zip_code NOT IN ".
"(SELECT zip_code from zip_cache)");
$results = $query->result_array();
foreach($results as $result){
$geocode_result = file_get_contents(
"http://maps.google.com/maps/geo?q=".
$result['zip_code'].
"&output=csv&key=$key");
$split_geocode_results =
explode(',', $geocode_result);
$lat = $split_geocode_results[2];
$long = $split_geocode_results[3];
$this->db->insert('zip_cache', array(
'zip_code' => $result['zip_code'],
'latitude' => $lat,
'longitude' => $long));
}
}
I can call this before every render of the map now. If a zip isn't in the cache table, it gets added. This really only happens when someone registers with a new zip, so it won't be all that often. Now I can map via the latitude and longitude, which is much more efficient and doesn't cause Google Maps to drop points.
Be sure to check out the map here: PodcampOhio Registration Map
Related posts:
- Google Maps Rocks I have a new mapping site: Google Maps. Google is...
- Does Google Index Hidden Divs? I was wondering recently if Google indexes hidden div tags....
- Fix for TiddlyWiki’s resolveTarget in IE I noticed the IE 6 wasn't happy when running the...
-
Joe
-
Keith Veleba