Mapping Phone Data in Four Easy Steps

Have you run into this problem: you have a list of phone numbers and associated values which would be best shown geographically to see patterns, but there isn't a clear way to put the data on a map. Maybe you'd like to see a map of customer service calls by call duration or inbound sales by average order size.

I wanted to share how to MacGyver a solution with a piece of twine, bubble gum, Excel, and a free online map tool. To me, this is a nice testament to the simple but powerful data visualizations that can be accomplished without programming skills or expensive applications.

1. Pull out area codes

First I pulled the area codes from my list of phone numbers using the formula below. This simply checks if the phone number starts with 1, then grabs the appropriate three digits for the area code.

=VALUE(IF(LEFT(E7,1)="1",MID(E7,2,3),MID(E7,1,3)))

2. Convert area codes into states

For my purposes, mapping the phone numbers by state was sufficient. Ideally, we would map the phone numbers to precise latitude and longitude coordinates by doing a reverse lookup of addresses then using the Excel geocoding tool.

First I needed a lookup table that could link my list of area codes to states. I wasn't able to track down a good data table, so I grabbed the data from All Area Codes and cleaned it up. Here is a lookup table of area codes by state.

An aside: I have a pet peeve with people who sell data that feels like it should be publicly available. You'll run across these businesses when looking for basic information about ZIP codes, MSAs, or area codes. Here is an example of one of these parasitic businesses.

Zip code product

3. Create your summary data set

I used a pivot table to summarize metrics by state.

4. Create colorized map of the US

Our friend Ducky Sherwood has generously put together a online tool called Mapeteria that will generate a colorized overlay of US states. In Ducky's words: "Want to make a choropleth thematic map (i.e. coloured based on your data) for Canadian provinces, U.S. states, or French départements?" This overlay can be viewed in either Google Maps or Google Earth.

Here's where it gets a little tricky. You will need to provide Mapeteria with a URL to a properly structured CSV file. Posting a CSV file to a web server isn't trivial if you aren't running your own web site. I found one free service called FileDEN that did the job (other suggestions?). Beware all the advertising—and in all likelihood they immediately sold my e-mail address at registration. Nevertheless, you can upload a file here and it will give you a URL which can be used to create your map.

Here's an example of the results:

State Map

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.

5 comments


October 12, 2007
Tony said:

This is somewhat similar to MS MapPoint with the big difference being this one is FREE!

The difference is this one has a bit more eye-appeal. Maybe it's just the pic, but some of the states in white all blend together. It would be nice to see low-light outlines of the states. Also, what if you don't know your geography too well and need to find Nebraska, but aren't sure which one it is? :)

Also, drill-in functionality would be nice to be able to see within a state what the breakdown is.


October 12, 2007
Eric Moritz said:

I'm sure you know this but the census.gov provides a zip code to lat-long file here:
http://www.census.gov/tiger/tms/gazetteer/zips.txt

Other zip code data can be found here:
http://www.sdc.ucsb.edu/holdings/zip_codes.txt


October 16, 2007
Ken said:

Zach,

Nice article. One thing that may have made things quicker for you would be to use the "Get External Data" functionality in Excel on a website like this:

http://www.bennetyee.org/ucsd-pages/area.html

In fact, I used that table to re-create the process in our data browser (screencast here: http://www.kirix.com/blog/2007/10/16/mr-macgyver-meet-strata/).

Keep up the great work!


October 18, 2007
Bob Chatham said:

Good stuff. I've been using the RegEx 5.5 library to extract area codes, country codes etc. (You need to include a reference in your Excel workbook). Here's a sample VBA function:
----
Public Function regExpMatch(s As Variant, Optional p As Variant, Optional n As Variant) As Variant
'Return the nth match to pattern "p" of a regExp; defaults to 1st match if n is omitted
'If pattern p is omitted, defaults to token: "\s*(?:(\d+)|(\w+)|(.))"
'Return #VALUE error if n is greater than the number of matches
'Return NULL string if no match
'Otherwise, return the matched string
'
'------------- Sample patterns
' Country code of phone number: "^\s*\+\s*(\d+)"

Dim myRegExp As RegExp
Dim myMatches As MatchCollection
Dim myMatch As Match

If IsMissing(n) Then n = 1
If IsMissing(p) Then p = "\s*(?:(\d+)|(\w+)|(.))"

Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = p
Set myMatches = myRegExp.Execute(s)

If (myMatches.Count = 0) Then
regExpMatch = ""
Exit Function
End If

If (myMatches.Count < n) Then
regExpMatch = CVErr(xlErrValue)
Exit Function
End If

regExpMatch = myMatches(n - 1).Value

End Function
-----

Here's a great free tool that works well with Excel data -- just cut and paste date from Excel into their dialogue box. See tutorial for more options.

http://www.gpsvisualizer.com/
http://www.gpsvisualizer.com/tutorials/waypoints.html

Also, useful geolocation/ZIP tools at:

http://zips.sourceforge.net/#dist_calc


October 29, 2007
Chris Kennedy said:

Thanks for the article. Check out http://pages.google.com/ for random data-hosting needs (esp. for Google Maps).

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





GIS for the rest of us... or Another Excel-based Mapping Tool

A client recently asked us if we could help him find the five locations that have the most customers nearby. I dug into the annals of our blog to find two tools that together ("wonder twin powers activate... shape of mini-GIS solution") could solve this problem:

1. Juice geo-coding tool lets you get the precise latitude and longitude for a list of addresses and plot these locations in Google Earth.

2.ZIP code finder lets you enter a US address and returns zip codes within a certain number of miles of that address.

Led by our resident Excel guru David, we combined these features into an Excel tool that lets you answer common location-based questions such as:

  • How many libraries are within 10 miles of Worchester, MA?
  • Which cities have the most libraries within 10 miles? 20 miles?
  • Could I see the library locations on a map, please?

Here's how it works:

1. Drop your location information into the "Geocode data" tab. We are using the Yahoo geocoding service.

2. Go to the results tab and fill in the table with your selected location addresses and distances. Press "Calculate."

Download the Excel file here: Juice Distance Tool

We had a couple other features in mind, but thought it would be better to get some reader reaction before we loaded it up.

This tool is released under the MIT license.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.

10 comments | Show all comments only the last 5 are shown


July 1, 2007
Zach said:

Last I tried, Yahoo's geocoding service (the one baked into this tool) returns a lat/long value for just a zip code.


July 2, 2007
kelvin said:

This is a GREAT TOOL! but ya, I can't see the site names from the JUICE tool...however, geocode 3.1 xls works, BUT it ends with a debug error after it completes the macro. the end result file provides the site names tho, which is VERY HELPFUL for me! is there a way to plugin the address for each site name/location? that would be ideal.

I use this tool to help me assess the number of apartment complexes in a given area. VERY USEFUL for me to get a quick idea of competition in a particular area i'm looking to invest in!


February 12, 2008
Jerry said:

Chris (#4) It has nothing to do with Excel 2003. The outputKML macro is referring to wrong column numbers. I changed my Geocode tab to make the Name/Description column into two separate columns & then changed two lines to reflect it:
name = CStr(ActiveSheet.Cells(r, 7))
description = CStr(ActiveSheet.Cells(r, 8))


February 12, 2008
Jerry said:

If you're behind a firewall, the calls to http.send will fail ....

Function yahooAddressLookup(addr As String, Optional Row As Long) As String
' perform RESTian lookup on Yahoo
Dim response As String

URL = "http://local.yahooapis.com/MapsService/V1/geocode?appid=yahoo_test&location=" & addr

'Create Http object
If IsEmpty(http) Then Set http = CreateObject("WinHttp.WinHttpRequest.5.1")

'Send request To URL
http.Open "GET", URL

http.send
....
....

Only way around it is to add code for http options to work with proxy authentication


October 26, 2008
Eric said:

Do you guys know how I can implement something similar to your Excel geocoder into MS Access where I can use a table of address records instead of a sheet of address rows in Excel.

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





Google Earth/Google Maps Mashups

Yesterday, Google rolled out new mapping features for Google Earth and Google Maps. Many of these features are behind the scenes in the APIs, but there are great new capabilities that you will start to see. One thing I'm excited about is that KML—Google Earth's format for building sophisticated map overlays—has come to Google Maps.

Google demoed this at their Geo Developer day yesterday using one of our Google Earth overlays that shows US census bureau data by county mapped as a heatmap. It looks like this.

Male Female Ratios in New York State

Counties are displayed in a list on the left. When you click on a county, you get a nice popup showing statistics for that county.

There are a few limitations. Large KML files don't load in Google Maps, medium-sized files load very slowly—it seems Google is parsing the KML using Javascript.

The mapping toolkits provided by Google Maps, Google Earth, and Yahoo Maps beta are well on their way to becoming important business tools once developers figure out how to wire in your enterprise data.

Without further ado, here are some US census data maps for you to explore in Google Maps.

Population Density

Lighter is higher population density (white is 800+ people per square mile), Dark is lower population density (black is 2 or fewer people per square mile)

Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware District of Columbia Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming

Median Age

Lighter is older median age (white is 46.0 years median age), Dark is younger median age (black is 29.0 years median age)

Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware District of Columbia Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming

Male/Female Ratio

Lighter means more men than women (white is 55% men), Dark means more women than men (black is 45% men)

Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware District of Columbia Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.

5 comments


June 14, 2006
Coty Rosenblath said:

This is very cool--particularly having Google demo with your overlays. I assume this will mean SketchUp models will be viewable in Maps, too. Do you know?


June 14, 2006
Chris said:

Thanks, Coty. I'm not sure of the status on SketchUp. I'm guessing the models would be flattened, but it still may work to show floorplans and stuff like that.

There's a lot more testing that needs to be done.


November 7, 2006
Jason said:

I love this concept and would like to start building similar overlays. I have zero programming experience, where do I start?


March 8, 2007
Aidan said:

Great Google Earth/Map post - thanks for sharing. Is there some trick to getting KMZs to work on Google Maps? I have generated a set that work great on Google Earth, but they generate an error on Google Maps. Since your team is using KMZs, is there any trick?

Thanks!


March 26, 2009
Gautham Ramachandran said:

I have a quick Q regarding data ownership. If I create a Zip Code Map with some specific point locations using Google Maps, who owns the data. Does Google house that data on their servers?

Gautham.

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





Google Earth Enhancements: What the birdie brought

A little birdie told me that the Juice Analytics census data heatmaps were used at Google's Developer Day to show how Google Maps can now load Google Earth KML files. Very cool.

Google Earth KML files now have two important user interface features that I'm excited to try out. First up is progressive display of data. This means a KML file can show high level summary info when when a user is high above the earth and seamlessly show more detail as the user zooms in. This was only possible through network links in the current version of Google Earth and this will feel a lot more polished to users. The other important UI feature is folders can now support radio buttons (where only one thing can be selected at a time). The big deal here is it allows a user to explore points organized into multiple dimensions where you can only view a single dimension at a time. For instance, you might want to view your customers grouped by sales volume, types of products purchased, or industry. Choose which of these groupings you want to see and the others will be hidden.

Finally, viewing KML files in Google Maps is a potential home run. This increases the sophistication of what Google Maps can display and simplifies rollout of geographic information to an organization. Bravo, GE folks.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.

2 comments


June 13, 2006
Jessica Lee said:

Yes, we used your California median age map in our demo at Google Geo Developer Day to show off the new feature. Love your work! Thanks.


June 13, 2006
Chris said:

Thanks, Jessica.

Glad you like the work and I'm happy you got some good use out of it. I'm obviously enthused about the new additions. How many developers did you get for Geo Developer Day?

Chris

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





Google Earth Hacks: Floating the Navigation Panel

The Google Earth User Interface is controlled by a mysterious cabal directed by the Vatican. Whoops, check that - Da Vinci Code marketing cross-talk. The Google Earth User Interface is really controlled by a simple, easy-to-read, easy-to-modify XML file. This means it's easy to show, hide, or modify elements of the user interface. Here's an example.

Google Earth with floating navigation panel

Observe the floating navigation panel with more room for the Earth in Google Earth. The navigation panel can also be hidden, or dragged to a different screen. Convenient.

This change is simple to make by editing the Google Earth "kvw" (Keyhole View?) file. On my system, this is found at C:\Program Files\Google\Google Earth\kvw\default_lt.kvw. This is a simple text file. Open the file in a text editor and find the Navigation Panel windowStack. Change the location attribute to "float" as you see below.

Google Earth XML Configuration

Make a backup before you start making changes. More extreme changes are not kosher, resulting in Google Earth failing to start. Restoring the kvw file from backup will fix the problem.

[Added] OgleEarth provides directions on using this hack on Mac OS X.

For the Mac, right-click on the Google Earth application (when it is not running), select "Show package contents", then navigate on over to:

/Applications/Google Earth.app/Contents/MacOS/kvw/default_lt.kvw

Open it in a text editor and apply Juice Analytics' hack. 

Incidentally, the Google Earth map you see above is graphing hurricane paths of the last 5 years with color coded intensities using a Python KML library. Just trying to keep up with the Joneses (the Joneses, in this case, being the Timoney group with their excellent start to Google Earth based analytics).

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.

1 comment


December 15, 2007
hashim said:

requried starting google earth

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





Earlier writing