### Install Open Location Code Go Package Source: https://github.com/google/open-location-code/blob/main/go/README.md Installs the Open Location Code Go library into your GOPATH. This command fetches and installs the latest version. ```bash go get github.com/google/open-location-code/go ``` -------------------------------- ### Install Glog Dependency Source: https://github.com/google/open-location-code/blob/main/tile_server/README.md Install the Glog library, which is used for logging within the tile server. ```go go get github.com/golang/glog ``` -------------------------------- ### Run Open Location Code Example Source: https://github.com/google/open-location-code/blob/main/c/README.md Execute the example C++ file to see the library in action. Requires Bazel. ```bash bazel run openlocationcode_example ``` -------------------------------- ### Install Freetype Dependency Source: https://github.com/google/open-location-code/blob/main/tile_server/README.md Install the Freetype library, used for rendering labels in PNG tiles. ```go go get github.com/golang/freetype ``` -------------------------------- ### Install YAPF for Code Formatting Source: https://github.com/google/open-location-code/blob/main/python/README.md Install YAPF, a Python code formatter, by first ensuring pip is installed and then installing YAPF using pip. ```bash wget https://bootstrap.pypa.io/get-pip.py sudo python get-pip.py ``` ```bash pip install --user yapf ``` -------------------------------- ### Install RuboCop Source: https://github.com/google/open-location-code/blob/main/ruby/README.md Install RuboCop for code formatting checks. Run with `rubocop --config rubocop.yml`. ```bash gem install rubocop rubocop --config rubocop.yml ``` -------------------------------- ### Install Open Location Code Library Source: https://context7.com/google/open-location-code/llms.txt Installation instructions for the Open Location Code library across different package managers and platforms. ```bash pip install openlocationcode ``` ```bash go get github.com/google/open-location-code/go ``` ```xml com.google.openlocationcode openlocationcode 1.0.4 ``` ```html ``` -------------------------------- ### Install Go-Fuzz Source: https://github.com/google/open-location-code/blob/main/go/README.md Installs the Go-Fuzz tool, which is used for fuzz testing the Open Location Code library. ```bash go get github.com/dvyukov/go-fuzz/... ``` -------------------------------- ### Start the Tile Server Source: https://github.com/google/open-location-code/blob/main/tile_server/README.md Run the Go tile server from the command line. Ensure you are in the project's root directory. ```bash go run tile_server/main.go ``` -------------------------------- ### Prepare for PyPi Release Source: https://github.com/google/open-location-code/blob/main/python/README.md Install necessary packages, setuptools and twine, for releasing the Python library to PyPi. ```bash pip install setuptools pip install twine ``` -------------------------------- ### Build and Test with Maven Source: https://github.com/google/open-location-code/blob/main/java/README.md Compiles the library, runs tests, and outputs a JAR file. Ensure Maven is installed on your system. ```bash $ mvn package ... ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.google.openlocationcode.EncodingTest Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.045 sec Running com.google.openlocationcode.PrecisionTest Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec Running com.google.openlocationcode.RecoverTest Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec Running com.google.openlocationcode.ShorteningTest Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec Running com.google.openlocationcode.ValidityTest Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec Results : Tests run: 13, Failures: 0, Errors: 0, Skipped: 0 ... [INFO] BUILD SUCCESS ``` -------------------------------- ### Install Open Location Code Dependency Source: https://github.com/google/open-location-code/blob/main/tile_server/README.md Install the Open Location Code library, which is used to generate codes for tile labels. ```go go get github.com/google/open-location-code ``` -------------------------------- ### Install Open Location Code Python Library Source: https://github.com/google/open-location-code/blob/main/python/README.md Install the library using pip. This is the standard method for adding Python packages to your environment. ```bash pip install openlocationcode ``` -------------------------------- ### Run Tests Source: https://github.com/google/open-location-code/blob/main/ruby/README.md Install the test-unit gem and run the Plus Codes tests. This command executes the test suite for the library. ```bash gem install test-unit ruby test/plus_codes_test.rb ``` -------------------------------- ### Install Orb Dependency Source: https://github.com/google/open-location-code/blob/main/tile_server/README.md Install the Orb library, which provides GeoJSON and Mapbox Vector Tile response objects. ```go go get github.com/paulmach/orb ``` -------------------------------- ### Install Plus Codes Gem Source: https://github.com/google/open-location-code/blob/main/ruby/README.md Install the plus_codes gem manually using the gem command. ```bash $ gem install plus_codes ``` -------------------------------- ### OpenLayers Integration Example Source: https://github.com/google/open-location-code/blob/main/tile_server/README.md Example of integrating the tile server with OpenLayers to display grid overlays. This snippet shows how to add a tile layer using the XYZ source pointing to the tile server. ```javascript var imageMap = new ol.Map({ target: 'imagemap', layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }), new ol.layer.Tile({ source: new ol.source.XYZ({ attributions: 'lus.codes grid', url: 'http://localhost:8080/grid/tms/{z}/{x}/{y}.png' }), }), ], view: new ol.View({ center: ol.proj.fromLonLat([8.54, 47.5]), zoom: 4 }) }); ``` -------------------------------- ### Build JAR with Bazel Source: https://github.com/google/open-location-code/blob/main/java/README.md Builds the Open Location Code JAR file using Bazel. Ensure Bazel is installed on your system. ```bash $ bazel build java:openlocationcode INFO: Found 1 target... Target //java:openlocationcode up-to-date: bazel-bin/java/libopenlocationcode.jar INFO: Elapsed time: 3.107s, Critical Path: 0.22s $ ``` -------------------------------- ### Encode Latitude/Longitude or Decode Global Code Source: https://github.com/google/open-location-code/blob/main/Documentation/Reference/plus.codes_Website_API.md This example shows how to convert a latitude and longitude to a Plus Code, or how to get the geometry of a global code. A Google API key is not required for these operations. ```APIDOC ## GET /api ### Description Converts a latitude and longitude to a Plus Code, or retrieves the geometry of a global Plus Code. ### Method GET ### Endpoint https://plus.codes/api?parameters ### Parameters #### Query Parameters - **address** (string) - Required - The address to encode. Can be a latitude/longitude pair or a global code. - **email** (string) - Recommended - An email address for contact. ### Request Example (Latitude/Longitude) https://plus.codes/api?address=14.917313,-23.511313&email=YOUR_EMAIL_HERE ### Request Example (Global Code) https://plus.codes/api?address=796RWF8Q%2BWF&email=YOUR_EMAIL_HERE ### Response #### Success Response (200) - **plus_code** (object) - Contains the Plus Code information. - **global_code** (string) - The generated global Plus Code. - **geometry** (object) - The bounding box and center of the Plus Code. - **bounds** (object) - The bounding box. - **northeast** (object) - Northeast corner coordinates. - **lat** (number) - Latitude. - **lng** (number) - Longitude. - **southwest** (object) - Southwest corner coordinates. - **lat** (number) - Latitude. - **lng** (number) - Longitude. - **location** (object) - The center coordinates. - **lat** (number) - Latitude. - **lng** (number) - Longitude. - **status** (string) - The status of the request (e.g., "OK"). ### Response Example { "plus_code": { "global_code": "796RWF8Q+WF", "geometry": { "bounds": { "northeast": { "lat": 14.917375000000007, "lng": -23.511250000000018 }, "southwest": { "lat": 14.91725000000001, "lng": -23.511375000000015 } }, "location": { "lat": 14.917312500000008, "lng": -23.511312500000017 } } }, "status": "OK" } ``` -------------------------------- ### Example API Request (Global Code to Geometry) Source: https://github.com/google/open-location-code/blob/main/Documentation/Reference/plus.codes_Website_API.md This request shows how to retrieve the geometry (bounding box and center) for a given global Plus Code. The '+' character in the Plus Code must be URL-encoded as '%2B'. Replace 'YOUR_EMAIL_HERE' with your email. This example does not require a Google API key. ```URL https://plus.codes/api?address=796RWF8Q%2BWF&email=YOUR_EMAIL_HERE ``` -------------------------------- ### Example API Requests with Google API Key Source: https://github.com/google/open-location-code/blob/main/Documentation/Reference/plus.codes_Website_API.md These are example URLs for making requests to the Plus Codes API. Ensure you replace YOUR_ENCRYPTED_KEY and YOUR_EMAIL_HERE with your actual credentials. The API key is required for full functionality, including short codes and localities. ```URL https://plus.codes/api?address=14.917313,-23.511313&ekey=YOUR_ENCRYPTED_KEY&email=YOUR_EMAIL_HERE ``` ```URL https://plus.codes/api?address=796RWF8Q%2BWF&ekey=YOUR_ENCRYPTED_KEY&email=YOUR_EMAIL_HERE ``` ```URL https://plus.codes/api?address=WF8Q%2BWF%20Praia%20Cape%20Verde&ekey=YOUR_ENCRYPTED_KEY&email=YOUR_EMAIL_HERE ``` -------------------------------- ### Example API Request (Latitude/Longitude to Plus Code) Source: https://github.com/google/open-location-code/blob/main/Documentation/Reference/plus.codes_Website_API.md This request demonstrates how to convert a latitude and longitude into a Plus Code. Ensure the URL is properly encoded, and replace 'YOUR_EMAIL_HERE' with your actual email address. This example does not require a Google API key. ```URL https://plus.codes/api?address=14.917313,-23.511313&email=YOUR_EMAIL_HERE ``` -------------------------------- ### Locality Request Example Source: https://github.com/google/open-location-code/blob/main/Documentation/Reference/plus.codes_Website_API.md This example demonstrates a request using a large feature like a city name for the address parameter. The returned Plus Code may have reduced precision, representing the largest code that fits within the feature's bounding box. ```URL https://plus.codes/api?address=Paris&ekey=YOUR_ENCRYPTED_KEY&email=YOUR_EMAIL_HERE ``` -------------------------------- ### Run PostgreSQL Docker Image Source: https://github.com/google/open-location-code/blob/main/plpgsql/README.md Starts a PostgreSQL Docker image named 'pgtest' and maps port 5433 to the container's 5432. ```shell docker run --name pgtest -e POSTGRES_PASSWORD=postgres -d -p 5433:5432 postgres ``` -------------------------------- ### Run Closure Library Tests with Bazel Source: https://github.com/google/open-location-code/blob/main/js/closure/README.md Provides the command to execute the Open Location Code tests for the Closure library using Bazel. Ensure Bazel is installed on your system. ```shell $bazel test js/closure:openlocationcode_test ``` -------------------------------- ### Build JAR Manually Source: https://github.com/google/open-location-code/blob/main/java/README.md Compiles the Java source files manually to create a JAR file in the build directory. This is an alternative if Bazel cannot be installed. ```bash mkdir build javac -d build src/main/java/com/google/openlocationcode/OpenLocationCode.java ``` -------------------------------- ### Google Maps API Image WMS Tiles Source: https://github.com/google/open-location-code/blob/main/tile_server/example.html Example using Google Maps API to display WMS image tiles. ```javascript // Google Maps API example, with WMS image tiles. var googleImageMap = new google.maps.Map( document.getElementById('g_image_wms'), { zoom: 4, center: {lat: 47.5, lng: 8.54} } ); var googleImageTiles = new google.maps.ImageMapType({ getTileUrl: function(coord, zoom) { return [gridServer, 'wms/', zoom, '/', coord.x, '/', coord.y, '.png'].join(''); }, tileSize: new google.maps.Size(256, 256) }); googleImageMap.overlayMapTypes.push(googleImageTiles); ``` -------------------------------- ### Encrypt Google API Key (Bash) Source: https://context7.com/google/open-location-code/llms.txt Example of using `curl` to encrypt a Google API key for secure use in client-side requests via the plus.codes Web API. ```bash # Encrypt your Google API key for safe use in client-side requests curl "https://plus.codes/api?encryptkey=my_google_api_key" # Returns: { "key": "", "status": "OK" } ``` -------------------------------- ### Lookup by Street Address (Bash) Source: https://context7.com/google/open-location-code/llms.txt Example of using `curl` to query the plus.codes Web API by a street address, which requires a Google API key. ```bash # Lookup by street address (requires key) curl "https://plus.codes/api?address=1600+Amphitheatre+Pkwy,+Mountain+View,+CA&key=YOUR_KEY" ``` -------------------------------- ### Recover Nearest Location (JavaScript) Source: https://context7.com/google/open-location-code/llms.txt JavaScript example for recovering the nearest full Plus Code using a short code and reference coordinates. ```javascript var full = OpenLocationCode.recoverNearest("9G8F+6W", 47.4, 8.6); console.log(full); // "8FVC9G8F+6W" ``` -------------------------------- ### Detect Global Plus Codes with Regex (Python) Source: https://context7.com/google/open-location-code/llms.txt Python example using the `re` module to define and compile a regular expression for detecting full (global) Plus Codes in text. The regex is case-insensitive. ```python import re from openlocationcode import openlocationcode as olc # Regex for global codes (full 10+ character codes) GLOBAL_CODE_RE = re.compile( r'(?:^|\s)([23456789C][23456789CFGHJMPQRV][23456789CFGHJMPQRVWX]{6}\+[23456789CFGHJMPQRVWX]{2,7})(?:\s|$)', re.IGNORECASE ) ``` -------------------------------- ### Test Go Implementation with GitHub Actions Source: https://github.com/google/open-location-code/blob/main/TESTING.md GitHub Actions workflow step for testing the Go implementation natively. It checks out code, sets up Go, and runs `go test`. ```yaml # Go implementation. Lives in go/ test-go: runs-on: ubuntu-latest env: OLC_PATH: go steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: go-version: 1.17 - name: test run: go test ./${OLC_PATH} ``` -------------------------------- ### GeoJSON Feature Example Source: https://github.com/google/open-location-code/blob/main/tile_server/README.md An example of a GeoJSON Feature object representing an Open Location Code grid cell. It includes geometry and properties like 'name', 'global_code', 'area_code', and 'local_code'. ```json { "type":"Feature", "geometry":{ "type":"Polygon", "coordinates":[ [ [-179.13587500002043, 83.52224999589674], [-179.13587500002043, 83.52237499589674], [-179.13575000002044, 83.52237499589674], [-179.13575000002044, 83.52224999589674] ] ] }, "properties":{ "area_code":"C2M2", "global_code":"C2M2GVC7+WM", "local_code":"GVC7+WM", "name":"C2M2GVC7+WM" } } ``` -------------------------------- ### Build Open Location Code JAR Source: https://github.com/google/open-location-code/blob/main/android_demo/android/libs/README.md Compile the Java source files and create a JAR archive. Ensure you are in the `java` directory of the cloned repository. ```bash cd open-location-code-master/java javac com/google/openlocationcode/OpenLocationCode.java jar -cfM ./openlocationcode.jar com/google/openlocationcode/OpenLocationCode$CodeArea.class com/google/openlocationcode/OpenLocationCode.class ``` -------------------------------- ### Run Go Benchmark Tests Source: https://github.com/google/open-location-code/blob/main/go/README.md Executes benchmark tests in addition to unit tests. The -bench=. flag runs all benchmarks. ```bash go test -bench=. . -v ``` -------------------------------- ### Run Go Unit Tests Source: https://github.com/google/open-location-code/blob/main/go/README.md Executes all unit tests within the 'go' directory. Use the -v flag for verbose output. ```bash go test . -v ``` -------------------------------- ### Leaflet Image TMS Tiles Source: https://github.com/google/open-location-code/blob/main/tile_server/example.html Example using Leaflet to display TMS-numbered image tiles. ```javascript // Leaflet example, with Openstreetmap map tiles and TMS-numbered image tiles. var llImageMap = L.map('ll_image_tms', {maxZoom: 21}).setView([47.5, 8.54], 4); L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors'} ).addTo(llImageMap); L.tileLayer( gridServer + 'tms/{z}/{x}/{y}.png', { tms: true, attribution: 'grid by Plus Codes' } ).addTo(llImageMap); ``` -------------------------------- ### Run Tests with Bazel Source: https://github.com/google/open-location-code/blob/main/java/README.md Builds the JAR and test classes, then executes all tests using Bazel. Run this command from the top-level github directory. ```bash $ bazel test java:all INFO: Found 1 target and 4 test targets... INFO: Elapsed time: 0.657s, Critical Path: 0.46s //java:encoding_Test PASSED in 0.4s //java:precision_test PASSED in 0.4s //java:shortening_test PASSED in 0.4s //java:validity_test PASSED in 0.4s Executed 4 out of 4 tests: 4 tests pass. $ ``` -------------------------------- ### Run Unit Tests with Bazel Source: https://github.com/google/open-location-code/blob/main/python/README.md Execute the unit tests and benchmarks for the Open Location Code Python library using Bazel. ```bash bazel test python:openlocationcode_test ``` -------------------------------- ### Release Python Library to PyPi Source: https://github.com/google/open-location-code/blob/main/python/README.md Build the source distribution and upload it to PyPi using twine. Ensure the version number in setup.py is updated before running. ```bash python setup.py sdist twine upload dist/* ``` -------------------------------- ### Build Open Location Code Library Source: https://github.com/google/open-location-code/blob/main/c/README.md Compile the Open Location Code C library using Bazel. This command builds the main library. ```bash bazel build openlocationcode ``` -------------------------------- ### OpenLayers Image TMS Tiles with Custom Colors Source: https://github.com/google/open-location-code/blob/main/tile_server/example.html Example using OpenLayers to display TMS-numbered image tiles with custom line and label colors. ```javascript // OpenLayers example, with Openstreetmap map tiles and TMS-numbered image tiles. var olImageMap = new ol.Map({ target: 'ol_image_tms', layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }), new ol.layer.Tile({ source: new ol.source.XYZ({ attributions: 'plus.codes', // XYZ layers use WMS tile numbering, use -y for TMS. url: gridServer + 'tms/{z}/{x}/{-y}.png?linecol=0xff0000ff&labelcol=0xff000060' }), }), ], view: new ol.View({ center: ol.proj.fromLonLat([8.54, 47.5]), zoom: 4 }) }); ``` -------------------------------- ### Lint JavaScript Code with ESLint Source: https://github.com/google/open-location-code/blob/main/js/closure/README.md Shows how to set up and run ESLint to check JavaScript code style and syntax within the js directory. This is crucial for maintaining code quality and passing CI tests. ```shell cd js npm install eslint eslint closure/*js ``` -------------------------------- ### Run Tile Server Tests Source: https://github.com/google/open-location-code/blob/main/tile_server/README.md Execute the Go tests for the tile server's projection functionality. The `--logtostderr` flag enables logging to standard error. ```bash go test ./tile_server/gridserver -v --logtostderr ``` -------------------------------- ### Encode Latitude and Longitude to OLC Source: https://github.com/google/open-location-code/blob/main/js/examples/example3.html Encodes a given latitude and longitude into an Open Location Code. This is the primary function to get an OLC for a specific point. ```javascript olcCode = OpenLocationCode.encode(event.latLng.lat(), event.latLng.lng()); ``` -------------------------------- ### Format Python Code with YAPF Source: https://github.com/google/open-location-code/blob/main/python/README.md Format Python files automatically using YAPF. This command checks and applies formatting according to the Google Python Style Guide. ```bash bash format_check.sh ``` ```bash python -m yapf --diff * ``` -------------------------------- ### Run All Bazel Tests Source: https://github.com/google/open-location-code/blob/main/TESTING.md Command to execute all tests defined in the Bazel build files. ```sh bazelisk test ...:all ``` -------------------------------- ### Format Go Code with gofmt Source: https://github.com/google/open-location-code/blob/main/go/README.md Ensures Go files adhere to standard formatting. Run this command to automatically format your project files. ```bash gofmt -w -s . ``` -------------------------------- ### OpenLayers Vector WMS Tiles with Zoom Adjust Source: https://github.com/google/open-location-code/blob/main/tile_server/example.html Example using OpenLayers to display WMS tiles with `zoomadjust=2` for more detailed grids. Clicking on a cell displays its Plus Code. ```javascript // Define the path to the Plus Code grid server. var gridServer = 'http://localhost:8080/grid/'; // OpenLayers example, with GeoJSON WMS tiles. // Create the vector layer. var olVectorLayer = new ol.layer.VectorTile({ source: new ol.source.VectorTile({ maxZoom: 25, attributions: 'plus.codes', format: new ol.format.GeoJSON(), // Using WMS tile numbering. url: gridServer + 'wms/{z}/{x}/{y}.json?zoomadjust=2' }), }); // Create the map, with Openstreetmap map tiles and the vector layer. var olVectorMap = new ol.Map({ target: 'ol_vector_xyz', layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }), olVectorLayer, ], view: new ol.View({ center: ol.proj.fromLonLat([8.54, 47.5]), zoom: 4 }) }); // Define an action so that clicking on the map will display the global code. var selectPointerMove = new ol.interaction.Select({ condition: ol.events.condition.click }); selectPointerMove.on('select', (e) => { document.getElementById("ol_vector_code").innerHTML = e.target.getFeatures().getArray()[0].get("global_code"); }); olVectorMap.addInteraction(selectPointerMove); ``` -------------------------------- ### Lookup by Short Code and Locality (Bash) Source: https://context7.com/google/open-location-code/llms.txt Shows how to use `curl` to look up a location using a short Plus Code combined with its locality information, requiring a Google API key. ```bash # Lookup by short code + locality (requires key) curl "https://plus.codes/api?address=WF8Q%2BWF%20Praia%20Cape%20Verde&key=YOUR_KEY" ``` -------------------------------- ### Encode Lat/Lng to Global Plus Code (Bash) Source: https://context7.com/google/open-location-code/llms.txt Example using `curl` to interact with the plus.codes Web API to encode latitude and longitude into a global Plus Code. Requires an email address. ```bash # Encode lat/lng → global Plus Code (no key required) curl "https://plus.codes/api?address=14.917313,-23.511313&email=your@email.com" # Response: # { # "plus_code": { # "global_code": "796RWF8Q+WF", # "geometry": { # "bounds": { # "northeast": { "lat": 14.917375, "lng": -23.511250 }, # "southwest": { "lat": 14.917250, "lng": -23.511375 } # }, # "location": { "lat": 14.917313, "lng": -23.511313 } # } # }, # "status": "OK" # } ``` -------------------------------- ### Generate Fuzzing Binaries Source: https://github.com/google/open-location-code/blob/main/go/README.md Generates necessary files for fuzz testing. This command should be run from the project root. ```bash go generate github.com/google/open-location-code/go ``` -------------------------------- ### Successful JSON Response Structure Source: https://github.com/google/open-location-code/blob/main/Documentation/Reference/plus.codes_Website_API.md This is an example of a successful JSON response from the Plus Codes API. It includes the global and local Plus Codes, geometry information, and locality details when an encrypted key is provided. ```JSON { "plus_code": { "global_code": "796RWF8Q+WF", "geometry": { "bounds": { "northeast": { "lat": 14.917375000000007, "lng": -23.511250000000018 }, "southwest": { "lat": 14.91725000000001, "lng": -23.511375000000015 } }, "location": { "lat": 14.917312500000008, "lng": -23.511312500000017 } }, "local_code": "WF8Q+WF", "locality": { "local_address": "Praia, Cape Verde" } }, "status": "OK" } ``` -------------------------------- ### Run Bazel Tests Source: https://github.com/google/open-location-code/blob/main/TESTING.md Command to run specific Bazel tests. Replace `:` with the actual directory and rule name. ```sh bazelisk test : ``` -------------------------------- ### JSON Response for Plus Code Conversion Source: https://github.com/google/open-location-code/blob/main/Documentation/Reference/plus.codes_Website_API.md This is an example of the JSON response received from the plus.codes API when converting a latitude/longitude to a global code or retrieving the geometry of a global code. It includes the global code, its bounding box, and center coordinates, along with a status indicator. ```JSON { "plus_code": { "global_code": "796RWF8Q+WF", "geometry": { "bounds": { "northeast": { "lat": 14.917375000000007, "lng": -23.511250000000018 }, "southwest": { "lat": 14.91725000000001, "lng": -23.511375000000015 } }, "location": { "lat": 14.917312500000008, "lng": -23.511312500000017 } } }, "status": "OK" } ``` -------------------------------- ### Initialize Google Map and OLC Event Listener Source: https://github.com/google/open-location-code/blob/main/js/examples/example3.html Initializes the Google Map and sets up an event listener for map clicks to display OLC boxes. Requires the Google Maps API. ```javascript google.maps.event.addDomListener(window, 'load', function() { map = new google.maps.Map( document.getElementById('map-canvas'), { center: new google.maps.LatLng(47.365561, 8.52494), zoom: 1, mapTypeId: google.maps.MapTypeId.ROADMAP, scaleControl: true }); map.setTilt(0); google.maps.event.addListener(map, 'click', mapClickHandler); geocoder = new google.maps.Geocoder(); }); ``` -------------------------------- ### Run Open Location Code Tests Source: https://github.com/google/open-location-code/blob/main/c/README.md Execute all tests for the Open Location Code library using Bazel. Ensure the test_data folder is copied to the root of your workspace. ```bash bazel test --test_output=all openlocationcode_test ``` -------------------------------- ### Compile Datafield with SDK on Linux Source: https://github.com/google/open-location-code/blob/main/garmin/PlusCodeDatafield/README.md Compile the datafield using the Connect IQ SDK on Linux. This command generates a .prg file for the simulator. ```shell ~/connectiq/bin/monkeyc -w -y ~/developer_key -f monkey.jungle -o bin/PlusCodeDatafield.prg ``` -------------------------------- ### Test Python Implementation with Bazel via GitHub Actions Source: https://github.com/google/open-location-code/blob/main/TESTING.md GitHub Actions workflow step for testing the Python implementation using Bazel. It supports multiple Python versions and runs `bazelisk test`. ```yaml # Python implementation. Lives in python/, tested with Bazel. test-python: runs-on: ubuntu-latest env: OLC_PATH: python strategy: matrix: python: [ '2.7', '3.6', '3.7', '3.8' ] name: test-python-${{ matrix.python }} steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: ${{ matrix.python }} - name: test run: bazelisk test --test_output=all ${OLC_PATH}:all ``` -------------------------------- ### Encode Lat/Lng with Google API Key (Bash) Source: https://context7.com/google/open-location-code/llms.txt Shows how to use the plus.codes Web API with a Google API key to obtain a local short code and locality name in addition to the global code. ```bash # With Google API key: returns local short code + locality name curl "https://plus.codes/api?address=14.917313,-23.511313&key=YOUR_API_KEY&email=your@email.com" # Adds to response: # "local_code": "WF8Q+WF", # "locality": { "local_address": "Praia, Cape Verde" } ``` -------------------------------- ### Instantiate OLCGridOverlay on Google Map Source: https://github.com/google/open-location-code/blob/main/js/contrib/README.md Instantiate the grid overlay by passing the map object to the OLCGridOverlay constructor or by using the setMap() method after instantiation. This is required before the overlay can be displayed. ```javascript // After you have created the Google Maps object, instantiate // the grid overlay, passing it the map object. var overlay = new OLCGridOverlay({map: map}); // Alternatively, use the setMap() method. var overlay = new OLCGridOverlay(); overlay.setMap(map); ``` -------------------------------- ### Export Datafield for Devices on Linux Source: https://github.com/google/open-location-code/blob/main/garmin/PlusCodeDatafield/README.md Export the datafield as a .iq file for specific devices using the Connect IQ SDK on Linux. This command assumes the SDK and developer key are in the specified paths. ```shell ~/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 ``` -------------------------------- ### Initialize Google Map and Add Click Listener Source: https://github.com/google/open-location-code/blob/main/js/examples/example1.html Initializes a Google Map and sets up a click listener to handle map interactions. This is the entry point for the OLC map functionality. ```javascript google.maps.event.addDomListener(window, 'load', function() { map = new google.maps.Map( document.getElementById('map-canvas'), { center: new google.maps.LatLng(47.365561, 8.52494), zoom: 1, mapTypeId: google.maps.MapTypeId.ROADMAP, scaleControl: true }); map.setTilt(0); google.maps.event.addListener(map, 'click', mapClickHandler); }); ``` -------------------------------- ### Format Code with rustfmt Source: https://github.com/google/open-location-code/blob/main/rust/README.md Format your Rust code using `rustfmt`. This command ensures code adheres to project formatting standards and will be checked by CI tests. ```bash cargo fmt ``` -------------------------------- ### Run Fuzz Tests Source: https://github.com/google/open-location-code/blob/main/go/README.md Executes fuzz tests using the compiled binary. Specify the binary path and a working directory for test corpus. ```bash go-fuzz -bin=./olc-fuzz.zip -workdir=/tmp/olc-fuzz ```