FaFre / open_location_code

Apache License 2.0
0 stars 0 forks source link

Docs with sample code #1

Open dryprogrammer opened 9 months ago

dryprogrammer commented 9 months ago

Hi, just came across your package. I also mentioned it in https://github.com/google/open-location-code/issues/569

Maybe you can use the following as a start for some docs:

Open Location Code (OLC) Dart Library Documentation

The open_location_code package is a Dart library for working with Open Location Codes (OLCs), also known as "plus codes". It provides several functions for encoding, decoding, validating, and manipulating OLCs.

  1. PlusCode class: This is the main class for working with OLCs. It includes the following methods:

    • PlusCode(): Constructor for creating a new PlusCode instance. It takes a string representing an OLC as an argument.
    • PlusCode.unverified(): Constructor for creating a new PlusCode instance without verifying the validity of the OLC. It's intended for bulk processing where the codes are known to be valid.
    • isValid(): Checks if the OLC is valid.
    • isShort(): Determines if the OLC is a valid short code.
    • isFull(): Determines if the OLC is a valid full code.
    • decode(): Decodes an OLC into the location coordinates.
    • recoverNearest(): Recovers the nearest matching code to a specified location.
    • shorten(): Removes characters from the start of an OLC.
    • encode(): Encodes a location into an OLC.
  2. PlusCodeValidator extension: This extension provides additional validation methods for the PlusCode class.

  3. Constants: The file includes various constants used in the OLC encoding and decoding process, such as pairResolutions, gridColumns, gridRows, decodeTable, and more.

  4. Helper functions: The file also includes helper functions used in the OLC encoding and decoding process.

PlusCode Class

The PlusCode class is the main class for working with OLCs. It includes the following methods:

PlusCode()

This is the constructor for creating a new PlusCode instance. It takes a string representing an OLC as an argument.

var plusCode = PlusCode('849VCWC8+Q9');

PlusCode.unverified()

This is a constructor for creating a new PlusCode instance without verifying the validity of the OLC. It's intended for bulk processing where the codes are known to be valid.

var plusCode = PlusCode.unverified('849VCWC8+Q9');

isValid()

This method checks if the OLC is valid.

var isValid = plusCode.isValid;

isShort()

This method determines if the OLC is a valid short code.

var isShort = plusCode.isShort();

isFull()

This method determines if the OLC is a valid full code.

var isFull = plusCode.isFull();

decode()

This method decodes an OLC into the location coordinates.

var codeArea = plusCode.decode();

recoverNearest()

This method recovers the nearest matching code to a specified location.

var recoveredPlusCode = plusCode.recoverNearest(LatLng(51.520847, -0.19552100));

shorten()

This method removes characters from the start of an OLC.

var shortenedPlusCode = plusCode.shorten(LatLng(51.520847, -0.19552100));

encode()

This method encodes a location into an OLC.

var encodedPlusCode = PlusCode.encode(LatLng(51.520847, -0.19552100));

PlusCodeValidator Extension

The PlusCodeValidator extension provides additional validation methods for the PlusCode class.

Constants

The file includes various constants used in the OLC encoding and decoding process, such as pairResolutions, gridColumns, gridRows, decodeTable, and more.

Helper Functions

The file also includes helper functions used in the OLC encoding and decoding process.

FaFre commented 9 months ago

Hi @dryprogrammer and thanks for the input :)

Tbh, I was not expecting anyone to show interest in this package really, especially since the google code was lingering in their repository for close to a decade without anyone taking the effort to push it to pub.dev

For now https://pub.dev/documentation/open_location_code/latest/open_location_code/open_location_code-library.html provides a pretty good documentation. Once I feel like there are people start using the library and are in demand of a quick start guide, I will put some effort.

Please just give me a sign in form of a comment here, future users :)

dryprogrammer commented 9 months ago

Oh I hadn't seen that. I guess Perplexity crawled that for me when it generated the docs.

Right, I'm new to geohash on dart, but didn't see any mention of OLC for a decade, despite all the benefits and compatibility with Geocoding API out-of-the-box.

Hopefully somebody will understand the potential and extend this in the future. :)