Map Scripting

Icon

Create Location-based Web Applications

Roll Your Own Postal Code Database

Many apps use zip codes to determine a user’s location. You can get the results with a geocoder service, or you can roll your own. From the same folks that supply the IP geolocation database, you can download one for U.S. zip codes.

The download is available as a direct database dump or CSV, like this:

"zipcode";"state";"fips_regions";"city";"latitude";"longitude"
"97002";"OR";"41";"Aurora";"45.2574";"-122.799"
"97005";"OR";"41";"Beaverton";"45.4924";"-122.803"

You’ll need to load it into a database and perform lookups yourself (ie, “select latitude, longitude from zips where zipcode=?”), but this is a good way to avoid wasting precious calls on fairly static and finite data.

Zip codes do change from time to time, so the database is updated periodically.

Looking for non-US postal codes? Check these out:

Location APIs: FourSquare, Latitude, etc

In addition to the W3C geolocation standard (I covered iPhone geolocation previously) and finding your user’s location based on IP, there are a number of services that let users actively share their whereabouts. Most of these services also have APIs, which allow you to access the shared locations (with the users permission, of course).

Here is a selection of location APIs and in some cases, tutorials that help you get started:

Which are your favorites? Am I missing any?

Add Search Radius with Circle Overlays

Searching within a specific distance of a point is a common mapping task. Yet, we rarely see the search area visualized, even though it’s rather easy to do. In the book I show two circle overlay methods: one approximates a circle with a polygon and the other overlays a graphic.

When using an image, you’ll want it to be a transparent PNG with the same width and height. The circle should just fit, so that it touches the edges of the graphic. The one I use in the example is swiped from Google Latitude and it’s on the left. Just right-click and choose the option to save the image.

Circle image from Google LatitudeCircle image from Google Charts

You can also create your own image using the Google Charts API wizard, like the border-less orange graphic above. Use its URL as a starting point at the bottom of the wizard.

If you make a graphic yourself, you’ll need to ensure that the PNG’s background is transparent. Otherwise, there will be a white box around your circle. You can make the circle itself semi-transparent, or rely upon the mapping API to display an opaque file at a percentage of its opacity.

For a working example of the polygon circle overlay, see this geocoded tweet mashup.

Use GPS “Tracks” from GPX Files

Many GPS units and even some mobile phone apps produce a GPX file, which contains a list of saved coordinates. These are usually called “tracks” and are useful for sharing or re-purposing where you’ve been. In the book, I show how to plot tracks on a map.

GPX tracks in Laurelhurst Park

The example from the book uses Portland’s Laurelhurst Park tracks (raw GPX file). If you’d like to create your own tracks with a mobile phone, check out My Tracks for Android or Trails for iPhone.

There are also sites to share GPX files, such as GPXchange.

Map Scripting 101 to the Printer

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.

Map Scripting 101 cover -- full bleed for printer

For those who are curious (and others wondering why this took 18 months), here’s the rough order of things:

  1. I write a first draft of a chapter and send it to Tyler Ortman, my editor at No Starch Press
  2. I almost certainly make some edits based on Tyler’s feedback
  3. Tyler sends the chapter to Derek Fowler for technical review
  4. I almost certainly make some edits based on Derek’s feedback
  5. Tyler sends the chapter to LeeAnn Pickerell, the copy editor
  6. I almost certainly make some edits based on LeeAnn’s feedback
  7. I package up the completed chapter, along with all the screenshots and figures and send them to Ansel Staton, No Starch’s production assistant
  8. Ansel sends me a PDF of the chapter and it starts to feel real
  9. I reply to Ansel and the production team’s questions
  10. Tyler sends the nearly-complete book to a proofreader and an indexer
  11. 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.

Happy 5th Birthday, Google Maps API

Google Maps API celebrates five years

It’s been five years since Google released the first version of its mapping API. Almost instantly the term “mashup” became synonymous with plotting data from one source on Google Maps. And since then, it’s gone from fun little toy to extremely useful tool. And while I appreciate all mapping APIs, it’s important to note this milestone for the influential platform. Let’s look where we are and how far we’ve come.

It’s easy to forget now, but the API followed some unofficial hacks (we celebrated this anniversary in April). Adrian Holovaty’s ChicagoCrime plotted public crime data in Chicago. Paul Rademacher’s HousingMaps let house hunters browse Craigslist visually. Holovaty’s site went on to become EveryBlock and roll its own mapping platform. Rademacher now works at Google.

Initial Reaction

There was tremendous excitement surrounding the announcement, Google making it official. Yet it’s quaint to realize that Google’s announcement came via a three sentence blog post and a spot on stage at the very first Where 2.0 Conference. It was not covered in TechCrunch–the site had barely launched.

I excitedly wrote about it on my own blog and quickly added maps to my Portland WiFi finder.

Everyone Adds a Mapping API

The Google Maps API probably didn’t take other map provider’s by surprise. Yahoo, for example, announced its API the following day. If it had been easier to use and wasn’t Flash-based, we might be living on a different geo web. Less than a month later Microsoft had Virtual Earth.

And around the same time the open source project Mapstraction was born. It now covers about a dozen mapping APIs with a single interface.

The Cutting Edge

It’s no longer enough to simply have a map. If it was, there wouldn’t have been much of a reason for me to write a book. Innovative developers will always push the boundaries, but here are some ways APIs are making it easier to create unique map apps:

  • Change your actual map imagery: Open Street Map beget CloudMade, which had to have inspired Google’s map styling. Now anyone can have a truly custom map.
  • Access data, where you want it: Administrating a geo database used to be hard. Now you can store your data in the cloud with My Maps Data or SimpleGeo. Or, if you want at public data, there are any number of sources to get just the information you need at the moment where you application needs it.
  • Mobilize your maps: The potential of the mobile web is being realized. Smart phones know our location and can display the Real Web on beautiful, touchable screens. Unfortunately, the bandwidth and processing power on a tiny little phone isn’t quite up to computer speeds. That means that the speed of mapping APIs is becoming even more important. That’s why we saw Google switch to version 3, which was initially built with mobile devices in mind.

Maps in 2015

Will this post look as quaint in five years as the Maps API announcements from 2005 do now? Probably. With as much as we’ve packed into the Map mashup era so far, we’re moving even faster now. Thanks to Google Maps–and the developers who use any mapping APIs–we’re just getting started exploring the world around us.

Start Here Guide Translated to Spanish: Traza En Español

For those who want a quick introduction to mapping on the web, I’ve offered my Start Here Guide for the last year. My full book is coming soon (did you know you can pre-order Map Scripting 101?), but the guide will remain. In fact, now it’s also available in Spanish.

I’m indebted to Claudio Cossio of Frontera Estates for not only the translation but the idea to offer a Spanish version in the first place. Thank you, Claudio!

So, regardless of whether you want it en ingles o en español, you can Download the Start Here Guide for free.

Map Scripting & Design

There are so many great tools for creating maps on the web, but so many maps are still boring (some of mine included!). There is an opportunity to set your maps apart, as I described in my SXSW talk. Also, the interaction with maps and their associated processes are still being figured out. This is another area where designers can make a huge impact.

I recently gave a talk at Refresh Portland with this message. I’ve embedded my slides below and pulled out a couple links I mentioned:

If you’re interested in walking through a map project together, from the basics to plotting data from outside services, I’m giving a half-day workshop, Hands On Map Scripting, at WebVisions.

Way Cool Map Scripting

Way CoolI presented a talk on moving beyond the typical map mashup today at SXSW Interactive in Austin. In it, I showed some simple ways to improve your maps, from using Mapstraction to custom map markers to changing the entire map imagery.

If you would like to get a feel for the presentation and examples, my “slides” are one giant HTML file. Really, it’s quite giant. So I’ve included the examples below. View the source, look around. Many of these are explained in detail in Map Scripting 101, but if you have questions I’d be happy to cover some more in-depth on this blog.

Map Math Behind a Virtual Grand Canyon Hike

The pedometer community site Walker Tracker added a new feature that plots your steps on a route around the rim of the Grand Canyon–or a handful of other locations. And you can invite your friends on the trip, with each avatar shown at a location determined by the user’s step count.

This is the site’s first foray into using maps. Ben, the site’s founder, contracted me to write much of the code for the new feature. Walker Tracker has an active community of step-counters who already take part in a number of competitions on the site. I’m happy to see this new competition type go live into Beta.

I used the site’s API to grab the current competition results and convert steps into a distance. That turns out to be the easy part, as the average person travels a mile in 2,000 steps. So, to keep things fair, we used that constant. No advantage for the long-legged!

Finding out which leg of the journey a user is on was also fairly easy. Once I knew the user’s distance, I could keep a running total of each leg until the next point would make it further than the user’s distance. Then I knew the user was between two particular points. On some routes, the points could be many miles apart. Walker Tracker needed to be more precise than that.

Find a Point Along a Route

The mapping challenge here was to plot the walker at just the right point along the route. That turns out to be a fairly complex problem and the solution has become a section in my book.

The example above shows three points. It’s a two step process to find point X, 0.3 miles between points A and B:

  1. Find the initial bearing (direction of travel) from point A to B
  2. Using the bearing, determine the point 0.3 miles along the route between points A and B

As for how to calculate the bearing and the point along the route, these scripts from Movable Type were immensely helpful.

Adam DuVanderHi, I'm Adam. I'm writing a book about developing maps on the web. This site is where I'll share the things I find and help you create your own maps. Find out more.

Map Scripting 101