Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining the distance between two ZIP codes (alternatives to mapdist)

I want to calculate the distance between approx. 100,000 different ZIP codes. I know about the mapdist function in the ggmap package

mapdist works perfectly:

library(ggmap)
mapdist('Washington', 'New York', mode = 'driving')

#         from       to      m      km    miles seconds  minutes    hours
# 1 Washington New York 366284 366.284 227.6089   13997 233.2833 3.888056


mapdist('20001', '10001', mode = 'driving')

#    from    to      m      km    miles seconds minutes    hours
# 1 20001 10001 363119 363.119 225.6421   13713  228.55 3.809167

However, mapdist relies on the Google Geocoding API which is subject to a query limit of 2,500 geolocation requests per day.

Are you aware of any alternative r code to calculate the distance between two points using another service which has a higher request limit (such as Nokia Maps or Bing)?

like image 820
majom Avatar asked Jun 28 '13 09:06

majom


People also ask

How are ZIP code boundaries determined?

As of 1963, zip codes' numbers are determined by a few factors: the area, the regional postal facility and the local zone. The first number of the five-digit code signifies the region which the address is located in, a number that grows from the east coast to the west.

Can I plot zip codes on a map?

You can map any kind of address data ranging from latitude and longitude coordinates to countries, states (provinces or regions), cities, zip codes, and/or specific addresses. Create a customized Google map by copying and pasting your excel or other spreadsheet data to make a map.

Can zip codes span multiple states?

ZIP codes can and do cross state lines (rarely, but just enough to cause some problems and confusion), county lines (about 10% of ZIPs are in more than one county), political jurisdictions (cities, congressional districts), metro areas, etc.


2 Answers

taRifx.geo::georoute (only available here until I push out another update, at which point it will be available via install.packages) can use Bing Maps (which supports I believe 25k per day) and can return a distance.

georoute( c("3817 Spruce St, Philadelphia, PA 19104", 
            "9000 Rockville Pike, Bethesda, Maryland 20892"), 
             verbose=TRUE, returntype="time", 
             service="bing" )

You'll have to get a Bing Maps API key and set it in your R global options (ideal placement is in .Rprofile), but the key is free:

options(BingMapsKey="whateverBingGivesYouForYourKey")
like image 137
Ari B. Friedman Avatar answered Nov 16 '22 00:11

Ari B. Friedman


This might be trivial, but one completely free option is to use Census ZCTA geography data to get co-ordinates for each zip code, and then calculate Haversine distances (or some similar distance metric) between coordinates.

like image 45
shreyasgm Avatar answered Nov 16 '22 02:11

shreyasgm