Guide to Google Plus Codes: Encoding & Decoding Locations

Practical examples and tips for implementing Google Plus Codes in your applications

Google Plus Codes enable recognition of isolated locations for navigation and delivery purposes
Google Plus Codes enable recognition of isolated locations for navigation and delivery purposes

Location information is crucial for industries like navigation, delivery services, and emergency response systems. Relying solely on traditional postal addresses can be limiting, even in cities. Additionally, certain locations lack specific addresses, such as open fields or temporary event venues. However, event organizers, attendees, and service providers still need a precise way to identify and navigate these sites.

Google Plus Codes (also know as Open Location Code) offer a practical solution by assigning a unique code to each location. This enables easy navigation and identification, even without a standard address. These codes provide an alternative method for encoding and decoding locations, allowing businesses to work with precise location information. Whether it's finding hidden spots on hiking trails, delivering to addressless buildings, or providing emergency services in remote areas, Google Plus Codes are a practical solution.

In this article, we will explore the concept of Google Plus Codes, their usability, and provide code samples. We will also demonstrate how to obtain Google Plus Codes using Geoapify's Geocoding API. By the end, you will have a clear understanding of Google Plus Codes and the tools necessary to integrate them seamlessly into your applications and services.

What Are Google Plus Codes

Google Plus Codes, also known as Open Location Code, is a location-based addressing system developed by Google. It provides a unique way to represent and identify any global location with a short alphanumeric code.

Plus Codes are generated based on latitude and longitude coordinates, which means they can be derived for any location worldwide. This universal coverage ensures that plus codes exist for every place on Earth. In terms of length, they are comparable to a telephone number, making them concise and easy to work with.

Here are a few examples of Google Plus Codes for different locations around the world:

  • Eiffel Tower, Paris, France: 8FW4V75V+8Q
  • Statue of Liberty, New York City, USA: 87G7MXQ4+P5
  • Taj Mahal, Agra, India: 7JVW52GR+2R
  • Sydney Opera House, Sydney, Australia: 4RRH46V8+42

It is often customary to exclude the first 4 characters of a plus code and append an approximate location, such as a city, state, or country. These abbreviated forms of plus codes can be utilized as a substitute for a specific house number within a neighborhood.

For instance, the "589R2QXQ+6R" referring to "Christ the Redeemer, Rio de Janeiro, Brazil" can be shortened to "2QXQ+6R Rio de Janeiro, Brazil" for easier reference. In other words, when we have a place in the city with the code "589R2QXQ+6R" and a city "Rio de Janeiro" with the code "589R3QQR+H7", we can replace the place's code first 4 characters by city name "2QXQ+6R Rio de Janeiro, Brazil".

Here are a few examples of shortened plus codes:

  • Acropolis of Athens, Athens, Greece: CG+M7 Athens, Attica, Greece
  • Brandenburg Gate, Berlin, Germany: G98H+G3 Berlin, Germany
  • Colosseum, Rome, Italy: VFRV+46 Rome, Lazio, Italy

The Benefits of Google's Plus Codes

Let's explore the benefits of Google's Plus Codes compared to traditional latitude/longitude coordinates, highlighting the advantages they offer in terms of openness and integration with Google and other Map services.

Google Plus Codes vs. Latitude/Longitude

Latitude and longitude coordinates, while widely recognized and offering precise location information, come with some disadvantages:

  • Lengthy Format: Latitude and longitude coordinates are typically represented in long decimal format, which can be challenging to work with and prone to errors during manual entry.
  • Manual Entry Challenges: The length and complexity of latitude and longitude coordinates make them difficult to enter accurately into devices manually, leading to potential mistakes.
  • Coordinate Swapping: There is a tendency for people to mistakenly swap the order of longitude and latitude coordinates, which can result in incorrect location identification and inaccurate results.

On the other hand, Google Plus Codes offer a simplified and alphanumeric alternative:

  • Shorter Code Format: Plus Codes convert latitude and longitude coordinates into a shorter alphanumeric code, making them easier to work with and remember.
  • User-Friendly: The alphanumeric format of Plus Codes is designed to be easily readable and writable, reducing the chances of errors during manual entry.
  • Widely Supported: Google, along with other mapping and navigation services, recognizes and supports the use of Plus Codes, ensuring their compatibility and availability across various platforms.

Open Source and Free to Use

Google Plus Codes not only provide a practical solution for location representation but also serve as an ideal choice for developers and businesses in need of a dependable and user-friendly solution for accurate location representation and seamless communication:

  • Open Source: The algorithms for Plus Codes was developed by Google in 2014, and since then, it has been made accessible to developers, businesses, and individuals without any cost.
  • Free to Use: Google Plus Codes are freely available to developers, businesses, and individuals without any licensing fees, making them accessible to a wide range of users.
  • Offline Functionality: Plus Codes can be encoded and decoded offline, enabling location identification and communication even in areas with limited or no internet connectivity.
  • NPM Libraries: Google provides NPM libraries and other software development resources for Plus Codes, simplifying the implementation process and reducing development time.

By offering an open-source, free-to-use standard, offline functionality, comprehensive platform support, and convenient development resources, Google Plus Codes demonstrate their superiority over other location code systems.

You can find the JSFiddle with the code sample here.

Encoding and Decoding of Geographical Coordinates

Let's check how to encode and decode geographical coordinates using Google Plus Codes with OpenLocationCode, an open-source NPM package. This library, released under the Apache 2.0 business-friendly license, offers an efficient solution for working with Plus Codes and boasts 0 dependencies.

You can convert a location into a Google Plus Code, and vice versa, without needing an internet connection or relying on online services. There are no complex data tables to look up or restrictions on using the algorithm. It's a straightforward and offline process, allowing you to easily work with Google Plus Codes anytime and anywhere.

You can easily install the OpenLocationCode using NPM or any other package management system:

npm i open-location-code

Encoding Locations to Plus Codes

The provided code snippet demonstrates how to use the OpenLocationCode library to encode geographical coordinates into Google Plus Codes:

const OpenLocationCode = require('open-location-code').OpenLocationCode;

const openLocationCode = new OpenLocationCode();

const loc = {lat: 38.726683, lon: -9.166475} // Aqueduto das Águas Livres, Lisbon, Portugal
const plusCode = openLocationCode.encode(loc.lat, loc.lon);

console.log(plusCode);

Executing this code will output the Google Plus Code corresponding to the specified location. For example, it might display something like "8CCGPRGM+MC" as the Plus Code for the Aqueduto das Águas Livres in Lisbon, Portugal.

In the following code snippet, we show the way to shorten the previously generated Plus Code for a specific location:

const cityLoc = {lat: 38.7077507, lon: -9.1365919} // Lisbon, Portugal
const plusCodeShort = openLocationCode.shorten(plusCode, cityLoc.lat, cityLoc.lon);

console.log(plusCodeShort + " Lisbon, Portugal");

Executing this updated code will output the shortened Google Plus Code followed by the city name and country. For instance, it may display something like "PRGM+MC Lisbon, Portugal" as the shortened Plus Code for the Aqueduto das Águas Livres, specifically located within Lisbon, Portugal.

Decoding Plus Codes to Locations

You usually need to validate the location code before decoding it. The code snippet demonstrates the usage of verification methods from the OpenLocationCode library to validate and determine the type of a Plus Code:

console.log(openLocationCode.isValid(plusCode));
console.log(openLocationCode.isValid(plusCodeShort));
console.log(openLocationCode.isValid("SOMECODE"));

console.log(openLocationCode.isFull(plusCode));
console.log(openLocationCode.isShort(plusCode));
console.log(openLocationCode.isFull(plusCodeShort));
console.log(openLocationCode.isShort(plusCodeShort));

Here we utilize the decoding capabilities of the OpenLocationCode library to retrieve the latitude and longitude values from Plus Codes:

const decoded = openLocationCode.decode(plusCode);
console.log({lat: decoded.latitudeCenter, lon: decoded.longitudeCenter});

const plusCodeNearest = openLocationCode.recoverNearest(plusCodeShort, cityLoc.lat, cityLoc.lon);
const decodedNearest = openLocationCode.decode(plusCode);
console.log({lat: decodedNearest.latitudeCenter, lon: decodedNearest.longitudeCenter});

To recover the nearest full Plus Code from the shortened version, first, you need to get the full plus code and then decode it.

You can find the full documentation for the OpenLocationCode library, including detailed information about its methods and usage, at the following link: OpenLocationCode Documentation >>

The documentation provides comprehensive guidance on how to work with OpenLocationCode, covering various functionalities, code examples, and additional resources to help you make the most of the library in your projects.

Plus Codes Integration in Geoapify Geocoding API

Plus Codes have gained widespread support and integration across various location platforms, making them a widely recognized and accepted standard. At Geoapify, we understand the value of Plus Codes in location representation and have incorporated them into our Geocoding API.

When using our Geocoding API, you can expect Plus Codes to be seamlessly integrated into the API response. Each geocoding result will include the full Plus Code and the shortened version for a more concise representation. Here is an example of the API result:

{
  "datasource": {
    "sourcename": "openstreetmap",
    "attribution": "\u00a9 OpenStreetMap contributors",
    "license": "Open Database License",
    "url": "https://www.openstreetmap.org/copyright"
  },
  "name": "Yellowstone Airport",
  "country": "United States",
  "country_code": "us",
  "state": "Montana",
  "county": "Gallatin County",
  "city": "West Yellowstone",
  "postcode": "59758",
  "street": "Cascade Avenue",
  "lon": -111.11688394311122,
  "lat": 44.6889409,
  "state_code": "MT",
  "distance": 0,
  "result_type": "amenity",
  "formatted": "Yellowstone Airport, Cascade Avenue, West Yellowstone, MT 59758, United States of America",
  "address_line1": "Yellowstone Airport",
  "address_line2": "Cascade Avenue, West Yellowstone, MT 59758, United States of America",
  "timezone": {
    "name": "America/Denver",
    "offset_STD": "-07:00",
    "offset_STD_seconds": -25200,
    "offset_DST": "-06:00",
    "offset_DST_seconds": -21600,
    "abbreviation_STD": "MST",
    "abbreviation_DST": "MDT"
  },
  "plus_code": "85PCMVQM+H6",
  "plus_code_short": "MVQM+H6 West Yellowstone, Montana, United States",
  "rank": {
    "importance": 0.27524463272973926,
    "popularity": 0.8547451172504956,
    "confidence": 0,
    "match_type": "full_match"
  },
  "place_id": "51c645ca067bc75bc0593b3025372f584640f00102f9019e00840d00000000c0020192031359656c6c6f7773746f6e6520416972706f7274",
  "bbox": {
    "lon1": -111.1337638,
    "lat1": 44.6697487,
    "lon2": -111.1053912,
    "lat2": 44.7033151
  }
}

Furthermore, our reverse geocoding feature enables you to obtain Plus Codes for a given set of geographical coordinates. Simply provide the latitude and longitude values, and our API will return the corresponding Plus Code for that location:

{
  "results": [
    ...
  ],
  "query": {
    "lat": 47.5284395940557,
    "lon": -122.59581163802147,
    "plus_code": "84VVGCH3+9M"
  }
}

By incorporating Plus Codes into our Geocoding API, we aim to provide developers and businesses with a comprehensive solution for location representation and communication. Whether you need to encode locations, decode Plus Codes, or leverage them in reverse geocoding, our API offers the necessary tools to seamlessly integrate Plus Codes into your applications and harness their benefits for enhanced location-based functionality.

Frequently Asked Questions

What are Google Plus Codes?

Google Plus Codes are an alternative method to represent location coordinates, providing a more readable and user-friendly format compared to traditional latitude and longitude coordinates. Instead of using lengthy and complex numerical values, Plus Codes use a combination of alphanumeric characters to encode a specific location. For example, instead of providing the latitude and longitude coordinates for a restaurant, you can simply provide its unique Plus Code, such as "GCPH+VX London, UK". This simplifies location sharing and navigation, especially in areas where traditional addresses may be limited or nonexistent. Plus Codes offer a practical solution for accurately pinpointing and referencing locations in a more accessible and user-friendly manner.

How do Google Plus Codes work?

Google Plus Codes divide the world into a grid system, assigning a unique code to each grid cell. The codes consist of a combination of letters and numbers, representing specific areas on the map. By encoding and decoding these codes, you can accurately determine the location they represent.

What are the benefits of using Google Plus Codes?

Google Plus Codes offer several advantages. They provide a user-friendly representation of locations, making it easier to communicate and share precise coordinates. Plus Codes are easy to read, write, and remember, making them ideal for manual input. They also provide additional context, such as the nearest address or reference point, enhancing navigation and communication purposes.

How can I obtain a Google Plus Code?

There are various methods to obtain a Google Plus Code. Online services, like Google Maps and plus.codes, allow you to generate Plus Codes for specific locations. Additionally, you can use geocoding APIs, such as Geoapify's Geocoding API, to retrieve Plus Codes programmatically based on geographical coordinates.

Can I use Google Plus Codes offline?

Yes, Google Plus Codes can be used offline. Since the codes are derived from latitude and longitude coordinates, they can be generated and decoded without the need for an internet connection and 3d party service. This makes Plus Codes a versatile and accessible solution, particularly in areas with limited connectivity.

Can I use Google Plus Codes worldwide?

Yes, Google Plus Codes can be used worldwide. They cover the entire globe and provide a consistent method of location representation across different countries and regions. Whether you are navigating remote areas, urban centers, or even places without traditional street addresses, Plus Codes offer a reliable and universal solution.

Are there any alternative location code systems to Google Plus Codes?

Yes, there are alternative location code systems available. Some examples include What3Words, Mapcode, and MGRS (Military Grid Reference System). These systems employ different algorithms and encoding methods to represent locations. It's important to choose the system that best suits your specific needs and integrates well with your applications and services.

Can I integrate Google Plus Codes into my own applications?

Absolutely! Google Plus Codes are designed to be easily integrated into various applications and services. You can utilize open-source libraries, such as OpenLocationCode, or leverage geocoding APIs like Geoapify's Geocoding API to encode, decode, and work with Plus Codes in your own software projects.

Are Google Plus Codes free to use?

A: Yes, the algorithms for Google Plus Codes are open source and free to use. Google introduced the Plus Codes system in 2014 and made it open source, which means that the algorithms and specifications are publicly available for developers and businesses to use without any licensing restrictions. This allows for transparency, collaboration, and the opportunity to customize and integrate Plus Codes into various applications and services. The open-source nature of Plus Codes promotes innovation and ensures that the technology remains accessible to all.