Archive Page 4



Chapter 3 encoding issues

UPDATE: added encoding fix.

A few savvy readers have pointed out an issue with the final map in Chapter 3. The example in the book wasn’t complete and does require additional work to be a fully functional but…In the scripts that store the information to the server I was simply adding an entry to an XML file. What I failed to mention (and didn’t include in the example) was that the input needs to be properly encoded to utf8 format and properly escaped to prevent HTML tag injection. The storeMaker.php example listing:

$lat = (float)$_GET['lat'];
$lng = (float)$_GET['lng'];
$found = $_GET['found'];
$left = $_GET['left'];
$icon = $_GET['icon'];

have been updated to include the appropriate fixes:

$lat = (float)$_GET['lat'];
$lng = (float)$_GET['lng'];
$found = htmlspecialchars(strip_tags(utf8_encode($_GET['found'])));
$left = htmlspecialchars(strip_tags(utf8_encode($_GET['left'])));
$icon = htmlspecialchars(strip_tags(utf8_encode($_GET['icon'])));

As well, the header in storeMarker.php and retrieveMarkers.php should include the appropriate charset.

header('Content-Type: text/xml;charset=UTF-8');

The map should now work as intended.

Update: Once you’re through with this article, there’s a followup that shows how to also make them clickable.

Many people find the object-oriented aspect of JavaScript to be very confusing. Fortunately, the designers of the Google Maps API have managed to make it extremely accessible—if all you ever did was instantiate their classes and then build scripts around those objects, you could still create very interesting and compelling maps. Creating a cool map is firstly about content, and secondly about technology.

However, there comes a point when you butt up against a limitation of the API, and it’s at that point that you can begin to explore the dynamic flexibility that JavaScript offers. To that end, I’d like to share a simple method of extending GMarker to allow for a text label to sit on each icon, like so:

Labeled Markers

But first, an announcement and disclaimer:

I am now working for Google. My school has a very strong co-op program, and as part of that, I was hired to work as an intern with the Maps Team in New York City for four months. As such, I cannot make any more speculative posts about future API or Maps features. And anything here that could be construed to be an opinion is not one held by my employer.

And with that out of the way, let me show you how to do labeled markers. Continue reading ‘Extending The API To Create Labeled Markers’

GPolygon is here

The API team has just announced the existence of a new API feature (since 2.69): The GPolygon.

Needless to say this is a feature we’ve been expecting for a while. A transparent, filled, polygon is something that many people have been trying to do for a while now, none of which were more than polyline or overlay hacks. The nearest we came was the state overlay demo that Mike explained in September.

I’m hoping that Mike can revisit the shape files example and do a GPolygon demo as a compliment to the custom tiles one from September. The logic of the shape-file parsing is still valid, but the rendering mechanism would be completely new.

Enjoy!

LinuxWorld: Google Maps API #1

Linux world has a roundup of the top 10 most useful, interesting and important Web 2.0 APIs that you can use for “real programming problems” in Web applications. At the top of their list is the Google Maps API, winning the #1 most important and influential API award.

I know many of you already agree with this, but for those of you who are joining us after recently receiving our book as a holiday gift, you’ve joined the right team. We’re here for the long-haul. :)

ZDNet Mistaken: API Terms of Use Simply Clarified

ZDNet is reporting that Google has updated the terms of use for their API to explicitly mention the geocoding API. ZDNet is wrong in stating that this is a new restriction since it’s been in place since the very first day the geocoding API was released.

The “new” restriction centers around the 50,000 lookups per day limit I discussed on June 21st, 2006 before our book was published 5 months ago.

I write this not to slap ZDNet for reporting dated news, but to instead make sure our more recent readers who have joined since June are aware of this restriction.

Happy Holidays from the three of us to all of you and yours.