I have a data set that includes a list of zip codes. Is there a way in R to convert these zip codes to latitude and longitude coordinates?

  • Latlong.net is a nice place for getting individual coordinates for a single zip code...
    – user43330
    Dec 25, 2014 at 0:32

5 Answers 5


There's no strict algorithmic relationship between latitude and longitude and zip code - they're all custom areas generated by the postal service. You need access to a dataset that codes polygons / polygon centroids by zip code.

1) Complex

Traditionally, this task (coupled with address lookup) is termed 'Geocoding'. The most convenient method for full address lookup is to find a preexisting online geocoder, whether by Google Maps, Bing Maps, or ESRI.

2) Simpler

For just US zip codes, though, there is data available from the Census:


I'm not familiar with R geospatial capability, but all you should need is polygon->centroid, and centroid->coordinates.

3) Simplest

This task is common enough that a preexisting centroid dataset exists: http://coolthingoftheday.blogspot.com/2008/04/free-us-zip-code-database-as-csv.html

  • 1
    Census Bureau link is broken. It probably referred to ZCTAs which are a census bureau invention. Originally based on zipcodes (which are NOT polygons and regularly change) these are polygons that are intended to be fairly constant. Ie. making them more usable for demographic purposes.
    – winwaed
    Jun 23, 2016 at 13:31

have you looked at the zipcode package? it's basically a dataframe with ~45,000 zipcodes along with their city, state, latitude and longitude.


I use the geocode function in the ggmap package.

  • will this allow zip+4 or does it only use zip centroids?
    – B_Miner
    Jun 22, 2012 at 17:49
  • It's using Google Maps, so works however Google would. (Only get a limited number of geocodes per day.)
    – Wayne
    Jun 22, 2012 at 17:50
  • ...and apparently you aren't allowed to store the data (you'd basically have to query the API about every time you need it)
    – Matt
    Jun 22, 2012 at 19:09
  • Do they mean you can't store them for future geocoding (i.e. creating your own cache of mappings), or that you can't store the results at all? I've used it to locate crimes in my neighborhood and certainly store the Lat/Lon of each crime for future reference. I haven't created a cache that I use to avoid Google for future geocoding, though.
    – Wayne
    Jun 22, 2012 at 19:40
  • 1
    My reading of the TOS (thanks for the link!) is that they have to do with the presenting of maps to other people. That is, you can't make your own map service that uses Google as a back end and doesn't credit them. It doesn't appear to have anything directly to do with geocoding data. Though who knows in this litigious era...
    – Wayne
    Jun 22, 2012 at 21:08

If you are dealing with few countries, there are some hints here

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Vince
    Dec 20, 2023 at 16:08

Seems like you are using Ruby on Rails
Try this tutorial from Ryan Bates http://railscasts.com/episodes/273-geocoder?view=asciicast
I've tried it before and it works perfectly. When you type address or zipcode , it will show the longitude and latitude.

  • 2
    He is asking for a solution in R, not Ruby on Rails.
    – Fezter
    Dec 3, 2012 at 3:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.