21152

Calculating the distance between ZIP Codes in R with the mapdist function

I am trying to use the mapdist function in R which relies on the Google Geocoding API. There are many pairs of ZIPs for which the mapdist function results in NA values. For instance:

mapdist('19111', '19187') by using this function you are agreeing to the terms at : http://code.google.com/apis/maps/documentation/distancematrix/ Information from URL : http://maps.googleapis.com/maps/api/distancematrix/json?origins=19111&destinations=19187&mode=driving&sensor=false from to km miles minutes hours 1 19111 19187 NA NA NA NA

But when I go into the Google Maps website it easily finds the correct answer which is about 13 miles. Does anyone know why this is happening? For many other pairs of ZIPs the function works perfectly. Thanks.

Answer1:

It could be that the zip code on its own is ambiguous. If you include 'USA' in the search string it works

library(ggmap) mapdist(from = c("19111, USA"), to = c("19187, USA")) # from to m km miles seconds minutes hours # 1 19111, USA 19187, USA 21420 21.42 13.31039 1976 32.93333 0.5488889

Or

library(googleway) set_key("your_api_key") google_distance(origins = c("19111, USA"), destinations = c("19187, USA")) # $destination_addresses # [1] "Philadelphia, PA 19187, USA" # # $origin_addresses # [1] "Philadelphia, PA 19111, USA" # # $rows # elements # 1 21.4 km, 21420, 33 mins, 1976, 35 mins, 2101, OK # # $status # [1] "OK"

Recommend

  • VBA code not returning values larger than 999
  • How to compute directed graph diameter in C++ [duplicate]
  • Add custom response header with Rack-cors and Grape
  • ms access check box
  • Error creating relationships over huge dataset
  • Move data from iSeries to DB2 Express?
  • java.lang.OutOfMemoryError: GC overhead limit exceeded when loading an xlsx file
  • About same origin policy…Can I do this?
  • POST Method not working in rack-cors rails 4
  • Docker container for google cloudML on compute engine - authenticating for mounting bucket
  • Youtube upload API and cordova / phonegap
  • Sencha Touch 2.1 native (android) app not getting json from remote (it works on PC)
  • Cannot page through all results using nextPageToken on YouTube search API v3
  • Can someone please explain to me in the most layman terms how to use EventArgs?
  • Eliminate partial duplicate rows from result set
  • Get history of file changes from TFS to implement custom “blame”-behaviour of exceptions
  • Keep this build forever option - Jenkins
  • iOS: Detect app start via notification press
  • How to attach a node.js readable stream to a Sendgrid email?
  • Play WS (2.2.1): post/put large request
  • Lost migrations and Azure database is now out of sync
  • Different response to non-authenticated users and AJAX calls
  • How would I use PHP exceptions to define a redirect?
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Hazelcast - OperationTimeoutException
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Web-crawler for facebook in python
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • RestKit - RKRequestDelegate does not exist
  • Circular dependency while pushing http interceptor
  • Linker errors when using intrinsic function via function pointer
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Revoking OAuth Access Token Results in 404 Not Found
  • SQL merge duplicate rows and join values that are different
  • How to set the response of a form post action to a iframe source?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Change div Background jquery
  • Is it possible to post an object from jquery to bottle.py?
  • Reading document lines to the user (python)