‘Tis the season where geeks and wannabe geeks ask their friends and loved ones for those things that haven’t yet bought themselves. For those who haven’t had a chance to buy Map Scripting 101 yet, I’d love to give it to you. Since I can’t give it to everybody, I decided to create a simple way to choose someone.
I call it Wishful Mapping. You add the book to your Amazon wishlist, then share it with me. I’ll randomly select someone to receive a copy of the book as a gift from me. And, of course, there’s also a good chance whoever else you share your wishlist with will get it for you.
After you’ve added the book to your wishlist, look for the Share With Friends link at the top of your wishlist.
Include email@example.com in the To: section. Increase your odds of receiving the book by including your the email addresses of others who might give you a gift. Only Amazon sees their email addresses.
And that’s it. Later this month I’ll select a random Wishful Mapper to receive Map Scripting 101 for free.
Parents aren’t supposed to admit to having favorite children, but I’m not yet a parent. Explore Proximity is my favorite chapter in the book. Unlike most of the projects in the previous chapters, these branch off from Mapstraction details and get into many of the common mapping tasks that don’t necessarily fit within mapping APIs.
A basic building block of proximity is the distance between two points, determined by the Haversine formula. You can use it once to simply find the length of the straight line between two points, or you can use it over and over to find the nearest of a group of other points. I cover this for both markers on a map and rows in a database.
Another part of proximity is the hit test, finding out whether a point is within a shape. For a box, like the screenshot above, it’s pretty easy. For a shape with any number of vertices? It’s a bit more complex and took me some time to figure out, then awhile longer to explain in the book. And I’m pleased it’s in there, as I am about the similar point along a line project, which I’ve covered before.
Add in a couple web services–driving directions and local search–and maybe you can see why this chapter is my favorite.
Easily one of the features most often overlooked by map mashups is the ability to tap into the map’s interactivity. I gave it an entire chapter in the book in hopes of encouraging you to “listen” for events in your applications.
For example, you can help your users identify a location by reacting to a map click. In fact, in chapter 4 I showed an example where the user can draw a line by connecting clicks.
Just as useful is knowing when the user moves or zooms the map. Then you can change what data you’re showing based on the new location or boundaries. Another use case I show for these events is to find out whether the user has moved outside pre-set bounds, such as Yellowstone National Park.
Other events covered include marker clicks, adding markers/polylines and opening/closing a message box. Use them and react to your user’s movements.
This chapter is where mapping starts to get really interesting, because it’s about more than the map and simple markers. There are 11 fun and useful projects, from drawing simple lines on the map to creating entirely new imagery to add as an overlay.
One of my favorite projects, for its high impact and easy implementation, is the circle overlay. You can use circles to show a search radius with just a few lines of Mapstraction and it makes a for a great visualization.
Other layering projects include drawing shapes (including the outlines of states/countries), using custom tiles and geo-referencing an image so it can be placed in the right location on the map.
Geocoding, converting addresses and city names into coordinates to place on the map, is such an important part of mapping, it’s hard to believe Google Maps launched without the feature. Now there are many geocoding services available, both within mapping APIs and from additional services, both free and paid. There’s also a greater need for reverse geocoders, which take a point on the map and return something human readable, like an address.
The book covers four types of geocoders:
Forward geocoding server-side
Reverse geocoding server-side
Reverse geocoders are becoming more popular because of mobile browsers. While in the past we almost always received our users’ locations from an address they type in, now we’re often receiving it directly, such as with the iPhone geolocation code, a standard that works across many browsers (including many desktop browsers). Coordinates help make coding easier, but sometimes you need to share with users where you think they are. Users don’t understand latitude/longitude, but they do understand addresses.
In addition to geocoding services, the book covers postal code databases. It is common for sites in the U.S. to request the user’s zip code, which is faster to type and less invasive than a full address. You can pass that off to a geocoding service to convert a code to, usually, the center of the postal code area. Or, you can install a postal code database yourself and not have to worry about building on top of another service, at least for postal code queries, which are fairly easy to identify.
Adding markers to a map is so central that I considered including it in chapter 1. However, because it’s such an important topic, it really deserved its own chapter. In addition to adding basic markers, I covered the way Mapstraction lets you customize your icon and do other cool things that aren’t included in standard mapping APIs.
In my talks about mapping at conferences, I tell developers that using a custom icon is by far the easiest thing you can do to make your map stand out from all the other mashups. And there’s really no reason not to do it in Mapstraction, as it’s just one more line, as I showed in the custom marker icons post.
Once you have a map full of markers, Mapstraction has a couple pretty cool features to deal with them. In another line of code you can automatically center and zoom the map so that all of them appear. And Mapstraction also lets you add any data you want to each marker, then filter upon that data.
As the title of the chapter suggests, it also covers message boxes, the little windows that pop up from markers to provide additional information. You can learn all about message boxes, filtering and everything else in this chapter by downloading chapter two for free from the publisher’s website.
The first chapter aims to get you started mapping quickly. It introduces a few concepts, like latitude/longitude, then gets right into creating maps and adding controls to them.
Among the most important projects in the entire book is my introduction of Mapstraction. I’ve written about Mapstraction quite a bit on this blog before, including one of the first posts. The open source library is the heart of almost every example in Map Scripting 101.
Mapstraction lets you write your code once and not worry much about changes to other providers. It helps provide an open interface to maps on the web, as I discussed in How Open Should Mapping APIs Be at Where 2.0 in 2009:
Like any good first chapter, Mapping Basics sets the foundation for the next nine chapters.
It’s done! We’ve fixed every last detail and the book is off to the printer. It’s been quite a process and it’s lovely to know the book will soon be in the press. Map Scripting 101 will hit shelves in early August.
For those who are curious (and others wondering why this took 18 months), here’s the rough order of things:
I write a first draft of a chapter and send it to Tyler Ortman, my editor at No Starch Press
I almost certainly make some edits based on Tyler’s feedback
Tyler sends the chapter to Derek Fowler for technical review
I almost certainly make some edits based on Derek’s feedback
Tyler sends the chapter to LeeAnn Pickerell, the copy editor
I almost certainly make some edits based on LeeAnn’s feedback
I package up the completed chapter, along with all the screenshots and figures and send them to Ansel Staton, No Starch’s production assistant
Ansel sends me a PDF of the chapter and it starts to feel real
I reply to Ansel and the production team’s questions
Tyler sends the nearly-complete book to a proofreader and an indexer
I make final changes and add an introduction/acknowledgments
Somewhere in there we chose the title, Tyler arranged for a cover design, the book was officially announced and No Starch worked up some snappy back cover copy.
Thanks all who have followed along! There’s plenty more mapping to happen here, as I’ll be previewing the various sections of the book and sharing the five mashup examples that wrap everything together.
Alternate title: that sure took longer than I thought.
It was a year ago today that I sat down to a blank OpenOffice screen and realized a book is a big project. Despite that, I intended to be done much sooner. And it’s not even done yet. The project continues, with technical review and copy editing happening right now.
I wrote about the writing process on my personal blog and I’m sure I’ll have more to say when the book is truly finished. But for now, thank you for following along. It’s been a fun year and I look forward to a great 2010 of more Map Scripting.
There’s still plenty to do. Every example will be looked over by a technical reviewer, to ensure that all the code works as expected. I will become good friends with No Starch’s copy editors. Finally, there are a few more mashups and projects I want to add to the book.