Documentation ¶
Overview ¶
Package pk provide part of https://github.com/Placekey/placekey-py features in pure Go. Most of codes translated from Python SDK. See details in https://docs.placekey.io/Placekey_Encoding_Specification_White_Paper.pdf
Placekey has two parts: `what` and `where`.
The `where` part. The core of `where` part is cut 21 bits of 64-bit integer which is a H3 integer, only use 43 bits left. Because the resolution is a const `10`, so each H3 id under the same resolution could remove common info. Then use alphabet represent the 43-bit integer as the `where` part of the whole place key.
The `what` part need use Placekey's API. Check API doc https://docs.placekey.io
Index ¶
- func GeoToPlacekey(lat, long float64) (string, error)
- func PlacekeyDistance(pk1 string, pk2 string) (float64, error)
- func PlacekeyToGeo(placekey string) (float64, float64, error)
- func PlacekeyToH3(placekey string) (*h3.Cell, error)
- func ValidatePlacekey(pk string) bool
- type Client
- type ClientOption
- type Response
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GeoToPlacekey ¶
Example ¶
package main import ( "fmt" "github.com/ringsaturn/pk" ) func main() { k, _ := pk.GeoToPlacekey(39.9289, 116.3883) fmt.Println(k) }
Output: @6qk-v3d-brk
func PlacekeyDistance ¶
Example ¶
package main import ( "fmt" "github.com/ringsaturn/pk" ) func main() { dist, _ := pk.PlacekeyDistance("@qjk-m7r-whq", "@hvb-5d7-92k") fmt.Printf("%.1f\n", dist/1000) }
Output: 13597.5
func PlacekeyToGeo ¶
PlacekeyToGeo convert placekey to latitude,longitude
Example ¶
package main import ( "fmt" "github.com/ringsaturn/pk" ) func main() { lat, long, _ := pk.PlacekeyToGeo("@6qk-v3d-brk") fmt.Printf("%.3f %.3f \n", lat, long) }
Output: 39.929 116.388
func PlacekeyToH3 ¶
PlacekeyToH3 convert placekey to H3 Index
func ValidatePlacekey ¶ added in v0.3.0
ValidatePlacekey will use Regex and H3 to validate Placekey's what(if provided) and where part.
Example ¶
package main import ( "fmt" "github.com/ringsaturn/pk" ) func main() { fmt.Println(pk.ValidatePlacekey("@627-wbz-tjv")) }
Output: true
Types ¶
type Client ¶ added in v0.2.0
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶ added in v0.2.0
func NewClient(apiKey string, opts ...ClientOption) (*Client, error)
func (*Client) GetPlacekeyFromAddress ¶ added in v0.2.0
func (c *Client) GetPlacekeyFromAddress( ctx context.Context, streetAddress string, city string, region string, postalCode string, isoCountryCode string, queryID string, ) (*Response, error)
GetPlacekeyFromAddress could get both what&where part of placekey.
type ClientOption ¶ added in v0.5.2
type ClientOption func(*Client)
func WithHTTPClient ¶ added in v0.5.2
func WithHTTPClient(httpClient *http.Client) ClientOption