Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Convert addresses to lat-longs (and vice versa) in Excel

License

NotificationsYou must be signed in to change notification settings

sanand0/geocode-excel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Download Geocode.xlsm.

This is an Excel file (with a Visual Basic macro function) that converts addresses to latitudes and longitudes (geocoding), and latitude-longitudes to addresses (reverse geocoding). This works through public geocoding APIs.

Requirements

  • It has been tested on Office 2017 and Office 365 on Windows.
  • It requires Excel 2013 or above (for theWorksheetFunction.EncodeURL method)
  • It only works on Windows. TheMSXML2 reference we use to access the APIs is not available on Mac.

Nominatim Geocoding functions

The Nominatim API uses OpenStreetMap, which is not as comprehensive as Google's but is free. See:https://nominatim.org/release-docs/develop/

=NominatimGeocode(address) Converts a string address (e.g. "10 Downing Street" or "Tokyo, Japan") into a "latitude,longitude" string=NominatimReverseGeocode(lat, lng) Converts a latitude and longitude into an address

NominatimGeocode usage

Google Geocoding functions

The Google Geocoding API is comprehensive, but requires an API key. See:https://developers.google.com/maps/documentation/geocoding/get-api-key

  • =GoogleGeocode(address, api_key) Converts a string address (e.g. "10 Downing Street" or "Tokyo, Japan") into a "latitude,longitude" string
  • =GoogleReverseGeocode(lat, lng, api_key) Converts a latitude and longitude into an address

The usage is otherwise identical to the Nominatim functions.

Tutorial

To get started, download and openGeocode.xlsm.

If you see a security warning, click on "Enable Content".

Excel security warning

In any cell, type in the formula=NominatimGeocode("10 Downing Street, London") in any cell. After a second, it shows the result as51.50344025,-0.127708209585621 — which is the<latitude>,<longitude> combination. Here's a live example:

Example of geocoding

Geocode an address

Visit thelist of the largest cities and copy the table, along with its population into Excel.

Addresses

If all the city names are in column A, you can create a new column with the formula=NominatimGeocode(A2) (replacingA2 with the actual cell reference).

Geocoding formula

Here, we useA2&", "&B2 to concatenate the city and nation. The first cell will look up “Chongqing, China”. When you press Enter, the result is:

Geocoding result

Geocode multiple addresses

Copy the formula into the entire column.

Result of copy-pasting the formula

Automatic calculations are disabled to reduce the number of API requests. So, if you copy-paste or drag a formula, the formula is not rerun. The values are copied as-is.

Instead, select asmall group of cells and pressCtrl-Q to run the RefreshSelected macro. (Each lookup takes 0.5 - 1 seconds. Select batches of 10-20 cells at a time.)

Once you finish geocoding, replace the formulas with the values. Otherwise, Excel will re-runthe entire geocoding every time you save, open, or refresh the file. To do this, copy the geocoded cells (Ctrl-C) and Paste Special > Values (Alt-H-V-S-V).

Excel Paste Special menu

This geocodes the selected cell range. Geocoded cells turn blue. But if there’s an error, these cells turn red.

Errors occur if the location contains special characters (e.g. the “ã” in São Paulo). In such cases, re-write the location in ASCII, i.e. without special characters (e.g. Sau Paulo.)

Geocoding error example

Split columns

To convert this single column with<latitude>,<longitude> into one column each, you can use Data >Text to Columns, and split the column using comma, as the separator.

Excel Text to Columns menu

The result is an Excel sheet with 2 columns: Latitude and Longitude.

Geocoded latitude-longitude columns

Exercises

  1. Geocode theairport locations in the UK
  2. Geocode thepost office locations in Singapore

Google Sheets alternatives

If you prefer using Google's Geocoders on Google Sheets, use:

About

Convert addresses to lat-longs (and vice versa) in Excel

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp