Open Location Code (Plus Codes)

repository·main·Indexed 26 days ago

https://github.com/google/open-location-code

A library to convert between latitude/longitude and Open Location Code (OLC) alphanumeric strings, designed as street address replacements for offline use and high precision. The project provides implementations in Java, C, C++, Dart, Go, and JavaScript, as well as a Garmin Connect IQ datafield.

Tokens
19K
Snippets
59
Records
152
Agent score
88%

What's inside open-location-code

  1. Overview of Open Location Code (Plus Codes)

    main

    Open Location Code (also known as Plus Codes) is a technology for encoding geographic locations into short, alphanumeric strings. It serves as a replacement for street addresses, particularly in areas without formal naming or numbering systems.

    Key Characteristics:

    • Area-based: Codes represent an area rather than a single point. Increasing the number of digits increases precision.
    • Offline Capability: Full codes can be encoded and decoded completely offline without lookup tables or internet access.
    • Similarity-based: Codes that are geographically close to each other tend to have similar character sequences.
    • Shortening: Codes can be shortened relative to a reference location for easier communication (e.g., 6GCRPR6C+24 can be shortened if a reference location is known).
    • Structure: Codes use a set of 20 digits that alternate between latitude and longitude. A + character is typically used after the first eight digits to distinguish them from postal codes.
  2. Understand Open Location Code (Plus Codes) characteristics

    main

    Open Location Code (also known as Plus Codes) is a location encoding system designed to provide usable addresses for locations without street addresses.

    Key features include:

    • Length: Full codes are 10 to 11 characters long. Short forms (4 to 7 characters) can be used within approximately 50km of the original location (or 2.5km for 4-5 character codes) by providing a nearby city or locality.
    • Structure: Includes a separator to distinguish codes from postal codes and aid human readability.
    • Area-based: Codes represent areas rather than points. Truncating a code increases the area size while still containing the original location.
    • Deterministic & Offline: Codes can be generated and decoded offline without any central infrastructure or provider dependency.
    • Usability: The character set excludes easily confused characters and vowels to prevent accidental word formation and improve memorization.
    • Proximity: Nearby locations share similar prefixes. There are discontinuities at longitude 180 and the north/south poles.
    • Uniqueness: There is only one Plus Code for a given location and area size.
  3. Use the Android Open Location Code Demonstrator

    main

    The Android Open Location Code Demonstrator is an Android application that demonstrates how to use Open Location Code (Plus Codes) on a mobile device.

    Key features include:

    • Displaying current location on a map.
    • Computing Open Location Codes for the current location.
    • Shortening codes using a bundled set of place names (currently configured for Cape Verde) to allow for offline address determination and location.

    Note: To use this project, you must have Android Studio installed.

  4. Understand Open Location Code (Plus Codes) basics

    main

    Open Location Code (also known as Plus Codes) is an open-source standard for expressing locations as short, easy-to-use alphanumeric codes. It serves as an alternative to traditional street addresses and latitude/longitude coordinates, especially in areas where street addresses are poorly defined or non-existent.

    Key characteristics:

    • Short and Memorable: Uses a higher number base (base 20) to keep codes shorter than latitude/longitude.
    • Flexible Precision: Supports various levels of precision (e.g., a 10-digit code covers ~14m x 14m, while an 11-digit code is more precise).
    • Offline Functionality: Codes can be generated and decoded without a data network.
    • Visual Proximity: Codes that are close to each other are often alphabetically similar, allowing for visual comparison.
    • Cultural Independence: Uses a specific character set designed to avoid common words and confusing characters.
  5. Install the VBA library in Microsoft Excel

    main

    To add Open Location Code functions to an Excel workbook:

    1. Open Excel and navigate to Tools > Macro > Visual Basic Editor.
    2. In the Project window, go to File > Import File.
    3. Select and import the OpenLocationCode.bas file.
    4. To verify the installation, go to Tools > Macro > Macros..., select TestOLCLibrary from the Macro name field, and click Run. A successful installation will display All tests pass.
  6. Install the VBA library in OpenOffice or LibreOffice

    main

    To use the library in OpenOffice or LibreOffice, you must enable VBA compatibility:

    1. Navigate to Tools > Macros > Organize Macros > Basic.
    2. Select your spreadsheet in the Macro From panel.
    3. Click New, name the module (e.g., OpenLocationCode), and click OK.
    4. Paste the entire contents of OpenLocationCode.bas into the editor.
    5. Crucial: Uncomment the following line at the top of the file to enable compatibility:
    Option VBASupport 1
    1. Save the file.
  7. Compile Plus Code datafield on Linux

    main

    To compile the datafield on Linux, you must have the Garmin Connect IQ SDK installed (e.g., in ~/connectiq) and a developer key (e.g., at ~/developer_key).

    Generate a .prg file for the simulator

    Run the following command to create a .prg file that can be used in the Connect IQ simulator:

    ~/connectiq/bin/monkeyc -w -y ~/developer_key -f monkey.jungle -o bin/PlusCodeDatafield.prg

    Generate an .iq file for all devices

    To build the .iq file containing binaries for each supported device (equivalent to the Export Wizard function), use the following command. This assumes the SDK is in ~/connectiq and your developer key is in ~/developer_key:

    ~/connectiq/bin/monkeyc -w -y ~/developer_key -f monkey.jungle -e -a ~/connectiq/bin/api.db -i ~/connectiq/bin/api.debug.xml -o PlusCodeDataField.iq -w -u ~/connectiq/bin/devices.xml -p ~/connectiq/bin/projectInfo.xml
  8. Build the Java Open Location Code library with Maven

    main

    To compile the library, run tests, and generate a JAR file using Maven, ensure Maven is installed on your system and run the package command from the java directory. The resulting JAR will be located in the target directory.

    $ mvn package
  9. Build and Install the Plus Code datafield

    main

    You can install the built version from the Garmin Connect IQ app store, or build it yourself.

    Standard Installation (Eclipse)

    If you are using the standard Garmin development process, open this directory in Eclipse to build.

    Linux Build Process

    If you are on Linux, ensure the Garmin Connect IQ tools are installed. You can compile the app using the monkeyc compiler. The resulting PlusCodeDatafield.prg file should be copied to the Garmin/Apps directory on your device, followed by a device restart to enable adding it to data screens.

    monkeyc -w -y developer_key.der -m manifest.xml -z resources/strings.xml -z resources/drawables.xml -z resources/layouts.xml -o bin/PlusCodeDatafield.prg source/*