diff --git a/osmshortlink.go b/osmshortlink.go index 254518d..2449c48 100644 --- a/osmshortlink.go +++ b/osmshortlink.go @@ -61,6 +61,7 @@ func interleaveBits(x uint32, y uint32) uint64 { return c } +// Decode a short string into a location and zoom. func Decode(s string) (float64, float64, int, error) { if len(s) < 1 { return 0, 0, 0, fmt.Errorf("invalid osm short link string %q", s) diff --git a/osmshortlink_test.go b/osmshortlink_test.go index 43221e5..5415be9 100644 --- a/osmshortlink_test.go +++ b/osmshortlink_test.go @@ -1,6 +1,7 @@ package osmshortlink import ( + "fmt" "math" "testing" ) @@ -199,3 +200,30 @@ func TestDecodeShortLinkString(t *testing.T) { }) } } + +func ExampleCreate() { + shortLink, err := Create(46.05141, 14.50604, 17) + if err != nil { + panic(err) + } + fmt.Println(shortLink) + // Output: https://osm.org/go/0Ik3VNr_A-?m +} + +func ExampleEncode() { + shortLink, err := Encode(46.05141, 14.50604, 17) + if err != nil { + panic(err) + } + fmt.Println(shortLink) + // Output: 0Ik3VNr_A- +} + +func ExampleDecode() { + latitude, longitude, zoom, err := Decode("0Ik3VNr_A-") + if err != nil { + panic(err) + } + fmt.Println(latitude, longitude, zoom) + // Output: 46.05140447616577 14.506051540374756 17 +}