osmshortlink

package module
v0.0.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2025 License: MIT Imports: 3 Imported by: 0

README

Go Reference Test golangci-lint CodeQL Go Report Card codebeat badge OpenSSF Scorecard GitHub Release

Specification: https://wiki.openstreetmap.org/wiki/Shortlink

Usage

package main

import "github.com/stefanb/osmshortlink-go"

func main() {
	shortlink, err := osmshortlink.Create(46.05141, 14.50604, 17)
	if err != nil {
		panic(err)
	}
	print(shortlink)
}

Prints: https://osm.org/go/0Ik3VNr_A-?m

Try it in Go playground

Command-line tool
Installation
Download the pre-built binaries

Download the pre-built binaries for your platform from latest release.

Install using Go
$ go install github.com/stefanb/osmshortlink-go/cmd/osmshortlink@latest
$ osmshortlink 46.05141 14.50604 17
https://osm.org/go/0Ik3VNr_A-?m
Run using Go without installing
$ go run github.com/stefanb/osmshortlink-go/cmd/osmshortlink@latest 46.05141 14.50604 17
https://osm.org/go/0Ik3VNr_A-?m
Pre-built binaries

You can download pre-built binaries for various platforms from latest release.

Usage: osmshortlink [latitude] [longitude] [zoom]

For example:

$ osmshortlink 46.05141 14.50604 17
https://osm.org/go/0Ik3VNr_A-?m

Development

Run: go run ./cmd/osmshortlink/main.go 46.05141 14.50604 17

Testing: go test -v -race -cover ./...

Fuzz testing: go test -fuzz=. -fuzztime=1m

Documentation

Overview

Creating OpenStreetMap short links, see https://wiki.openstreetmap.org/wiki/Shortlink

Index

Examples

Constants

View Source
const (
	BASE_SHORT_OSM_URL = "https://osm.org/go/"
)

Variables

This section is empty.

Functions

func Create

func Create(latitude float32, longitude float32, zoom int) (string, error)

Create a short link to OSM map with marker at he given position and zoom

Example
shortLink, err := osmshortlink.Create(46.05141, 14.50604, 17)
if err != nil {
	panic(err)
}
fmt.Println(shortLink)
Output:

https://osm.org/go/0Ik3VNr_A-?m

func Decode

func Decode(s string) (float64, float64, int, error)

Decode a short string into a location and zoom.

Example
latitude, longitude, zoom, err := osmshortlink.Decode("0Ik3VNr_A-")
if err != nil {
	panic(err)
}
fmt.Println(latitude, longitude, zoom)
Output:

46.05140447616577 14.506051540374756 17

func Encode

func Encode(latitude float32, longitude float32, zoom int) (string, error)

Encode a location and zoom, return a short string representing it.

Example
shortLink, err := osmshortlink.Encode(46.05141, 14.50604, 17)
if err != nil {
	panic(err)
}
fmt.Println(shortLink)
Output:

0Ik3VNr_A-

Types

This section is empty.

Directories

Path Synopsis
cmd
osmshortlink command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL