Archive Page 3



Rails Edition Contest!

Andre Lewis has been hard at work since September 2006 translating and rewriting the PHP-centric edition of our Beginning Google Maps Applications book into Ruby on RAILS — and we’re giving away 3 4 copies over the next 3 weeks!

If you’re interested in entering the contest please simply visit http://googlemapsbook.com/contest and fill out the form. We’ll randomly draw three winners on the 15th of March, 2007 and ship some shiny new books.

Please feel free to share the link with all of your friends and user groups. If we get an overwhelming response we may give away a few bonus copies to increase your odds of winning.

About our new book
All of the easy to follow examples that you’ve come to love from the PHP edition are still here, only they are now implemented in the Model-View-Controller paradigm that Rails uses at it’s core. The book won’t teach you RAILS anymore than our first book taught you PHP, but if you’re already familiar with RAILS then you will love the impressive and educational examples in this book.

For those of you who can’t wait three weeks to find out, Beginning Google Maps Applications with RAILS and Ajax is now available from our favorite online book retailer. A spare copy never hurt anyone :)

Andre Lewis has been hard at work writing our new sister book Beginning Google Maps with RAILS and Ajax. It’s due back from the printers in about a week, so on the eve of its release he has also released GeoKit for Rails along with Bill Eisenhauer. Bill also has a few examples on his site. Check them out.

From the site:

Geokit is a Rails plugin for building location-based apps. It provides geocoding, location finders, and distance calculation in one cohesive package. If you have any tables with latitude/longitude columns in your database, or if you every wanted to easily query for “all the stores within a 50 mile radius,” then GeoKit is for you.
What can GeoKit do for you?

  • Distance calculations between two points on the earth. Calculate the distance in miles or KM, with all the trigonometry abstracted away by GeoKit.
  • ActiveRecord distance-based finders. For example, you can find all the points in your database within a 50-mile radius.
  • Geocoding from multiple providers. It currently supports Google, Yahoo, Geocoder.us, and Geocoder.ca geocoders, and it provides a uniform response structure from all of them. It also provides a fail-over mechanism, in case your input fails to geocode in one service.
  • IP-based location lookup utilizing hostip.info. Provide an IP address, and get city name and latitude/longitude in return.
  • A before_filter helper to geocode the user’s location based on IP address, and retain the location in a cookie.

If this is interesting to you consider helping us get the word out for Andre and Bill by digging the announcement for them.

Keep an eye out for a chance to win a copy of his new book in the next few days and be the first in your local RUG to get it!

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!