-
Notifications
You must be signed in to change notification settings - Fork 46
/
example_test.go
72 lines (56 loc) · 1.56 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package geohash_test
import (
"fmt"
"github.com/mmcloughlin/geohash"
)
func Example() {
// Uluru in Australian Outback
lat, lng := -25.345457, 131.036192
// Encode a full 12 character string geohash
fmt.Println(geohash.Encode(lat, lng))
// Or at lower precision
fmt.Println(geohash.EncodeWithPrecision(lat, lng, 6))
// As an integer
fmt.Printf("%016x\n", geohash.EncodeInt(lat, lng))
// Decode to a point
fmt.Println(geohash.Decode("qgmpvf18"))
// or to a bounding box
fmt.Println(geohash.BoundingBox("qgmpvf18"))
// Output:
// qgmpvf18h86e
// qgmpvf
// b3e75db828820cd5
// -25.3454 131.036
// {-25.345458984375 -25.345287322998047 131.03599548339844 131.03633880615234}
}
func ExampleEncode() {
fmt.Println(geohash.Encode(48.858, 2.294))
// Output: u09tunq6qp66
}
func ExampleEncodeInt() {
fmt.Printf("%016x\n", geohash.EncodeInt(48.858, 2.294))
// Output: d0139d52c6b54c69
}
func ExampleEncodeIntWithPrecision() {
fmt.Printf("%08x\n", geohash.EncodeIntWithPrecision(48.858, 2.294, 32))
// Output: d0139d52
}
func ExampleEncodeWithPrecision() {
fmt.Println(geohash.EncodeWithPrecision(48.858, 2.294, 5))
// Output: u09tu
}
func ExampleDecode() {
lat, lng := geohash.Decode("u09tunq6")
fmt.Printf("%.3f %.3f\n", lat, lng)
// Output: 48.858 2.294
}
func ExampleDecodeInt() {
lat, lng := geohash.DecodeInt(0xd0139d52c6b54c69)
fmt.Printf("%.3f %.3f\n", lat, lng)
// Output: 48.858 2.294
}
func ExampleDecodeIntWithPrecision() {
lat, lng := geohash.DecodeIntWithPrecision(0xd013, uint(16))
fmt.Printf("%.3f %.3f\n", lat, lng)
// Output: 48.600 2.000
}