Documentation
¶
Overview ¶
Package thailocate resolves a WGS84 latitude/longitude coordinate to the Thai administrative area that contains it: province (จังหวัด), district (อำเภอ, or เขต inside Bangkok) and subdistrict (ตำบล, or แขวง inside Bangkok).
Boundary data is embedded in the compiled binary, so lookups never touch the network or disk at runtime.
Basic usage:
loc, err := thailocate.New()
if err != nil { ... }
detail, err := loc.GetLocationDetail(13.7563, 100.5018)
A ready-to-use default instance is also available without constructing one yourself:
detail, err := thailocate.GetLocationDetail(13.7563, 100.5018)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LocationDetail ¶
type LocationDetail struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Found bool `json:"found"`
CountryEN string `json:"country_en,omitempty"`
CountryTH string `json:"country_th,omitempty"`
ProvinceEN string `json:"province_en,omitempty"`
ProvinceTH string `json:"province_th,omitempty"`
ProvinceCode string `json:"province_code,omitempty"`
// District is the อำเภอ (Amphoe) — or เขต (Khet) for the 50 districts
// of Bangkok. DistrictType tells you which term applies.
DistrictEN string `json:"district_en,omitempty"`
DistrictTH string `json:"district_th,omitempty"`
DistrictCode string `json:"district_code,omitempty"`
DistrictType string `json:"district_type,omitempty"` // "amphoe" | "khet"
// Subdistrict is the ตำบล (Tambon) — or แขวง (Khwaeng) for Bangkok's
// subdistricts. SubdistrictType tells you which term applies.
SubdistrictEN string `json:"subdistrict_en,omitempty"`
SubdistrictTH string `json:"subdistrict_th,omitempty"`
SubdistrictCode string `json:"subdistrict_code,omitempty"`
SubdistrictType string `json:"subdistrict_type,omitempty"`
MatchLevel MatchLevel `json:"match_level"`
}
LocationDetail is everything thailocate knows about a coordinate.
func GetLocationDetail ¶
func GetLocationDetail(lat, lng float64) (*LocationDetail, error)
GetLocationDetail is a package-level convenience wrapper around a lazily initialized, shared Locator. Use this if you just want to call thailocate.GetLocationDetail(lat, lng) without managing a Locator yourself.
type Locator ¶
type Locator struct {
// contains filtered or unexported fields
}
Locator holds the parsed boundary polygons in memory and answers lookups. It is safe for concurrent use by multiple goroutines.
func New ¶
New parses the embedded boundary data and returns a ready-to-use Locator. This does a few megabytes of JSON parsing, so construct one Locator and reuse it (it's safe for concurrent use) rather than calling New per request.
func (*Locator) GetLocationDetail ¶
func (l *Locator) GetLocationDetail(lat, lng float64) (*LocationDetail, error)
GetLocationDetail resolves lat/lng (WGS84 decimal degrees) to the Thai province / district / subdistrict that contains it.
If the point falls outside Thailand, or in a gap in the simplified boundary data, Found is false and MatchLevel is "none" — this is not treated as an error, since "not in Thailand" is a perfectly valid answer. An error is only returned for malformed input.
type MatchLevel ¶
type MatchLevel string
MatchLevel indicates the finest administrative level that was actually resolved for a query. Lookups almost always resolve at the subdistrict level; province/district-only results are a rare fallback for points that fall in tiny gaps between simplified polygons (e.g. right at a coastline).
const ( MatchSubdistrict MatchLevel = "subdistrict" MatchDistrict MatchLevel = "district" MatchProvince MatchLevel = "province" MatchNone MatchLevel = "none" )
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
thailocate-server
command
Command thailocate-server exposes the thailocate library over HTTP.
|
Command thailocate-server exposes the thailocate library over HTTP. |
|
example
|
|
|
basic
command
|