The site should be checked using Firefox and Safari. It does not work in Internet Explorer (the map won't even draw!).
Since Google Maps require JavaScript, I didn't have a problem with using JavaScript to adjust the map height to fit the window (the div width was already liquid and didn't require adjusting). I used a resize event handler to get the height of the viewport, subtract the height of the header and footer divs and use the result to set the map div height.
I planned on doing something to cache RSS news even before people reported in the forum that Google was blocking our access to the Google News feeds because we were accessing it too often from the server's address. My chosen method was simple; before accessing the RSS feed getnews.php
checks to see if a file exists with the zip code as its name and if one does, checks if the file is less than 30 minutes old. If the file exists and isn't too old, it's used in lieu of the feed. If it doesn't exist or is too old the feed is accessed as usual and the zip code file is created/over-written.
At one point Google News started ignoring the GET variable to request a quantity, num=5
, so to the foreach loop that creates the item
elements in my XML object I added a counter that breaks the loop when it reaches "5" or whatever quantity I specify. Once I encountered an RSS feed that was invalid due to a bare ampersand (&) in it's title (for "US News & World Report"). This prevented the infoWindow from having any headlines. I tried crafting a regular expression to correct the error but I only figured out how to replace all the ampersands including those that were at the beginning of existing HTML entities.
The zip code table has the same coordinates for some zip codes. To avoid putting multiple markers on the same spot, latlng2zips.php
takes the SQL query results, puts them in an array, then uses array_unique()
to eliminate duplicate coordinates.
Following another student's idea, I chose not to use the provided stored procedure and instead used the map's Gbounds()
coordinates when looking up zip codes from the table. This also allows for searches to be made on any address that's valid to the geocoder, not just zip codes. For a high zoom level (> 12) every zipcode within the bounds is displayed. In the middle range, I reduced the number displayed by only showing one zip code per city ("GROUP BY city" in the SQL query). I also added "LIMIT 50" to the query because there were still too many in some areas. Even further out (< 8), only a single marker for state capitals is shown. To achieve this, I created a table of capitals with "city" and "abbr" fields then use tbl_zipcodes NATURAL JOIN tbl_capitals
in addition to the "WHERE" and "GROUP BY" parts of the SQL query. Major cities that are not capitals could also be added to the second table to fill out the map a bit.
The same zoom levels that determine which SQL query is performed also determine which icon is used. The furthest in and furthest out levels get the default icon. The middling zoom levels get a smaller icon so they're less cluttered in areas with many close cities and towns. In addition to having the zip code at the top of the infoWindow, the zip code is also in a tooltip on each marker. In areas with no zip codes (or no state capitals if the map is that zoomed out), instead of zip code markers a single marker is placed in the center of the map. The marker's infoWindow and tooltip simply say "No zipcodes."
I tried using the GMarkerManager for managing markers but it didn't seem to offer any benefit and it seemed to prevent the removal of markers when moving or zooming the map. At first I used a "moveend" event handler to redraw the markers when the user moved the map but it was also triggered by the panning necessary to show an infoWindow that needed more room. The panning move would delete the markers and infoWindow so AJAX request didn't have the div element to write the headlines to. Changing from "moveend" to "dragend" prevented the accidental triggering but also prevented the redrawing from happening when the up, down, left, right controls are used instead of click-dragging.
© 2008 Curtis Wilcox