Documentation
¶
Overview ¶
Package geodecode provides functionality to find the nearest geographical location (city, town) for a given latitude and longitude coordinate from a pre-loaded dataset. It utilizes a KD-Tree for efficient nearest neighbor searches.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCountryByCode ¶ added in v0.9.4
GetCountryByCode returns the full country name for a given ISO country code (e.g., "US", "GB"). It uses the github.com/biter777/countries package for lookup.
Example usage:
countryName := geodecode.GetCountryByCode("US")
fmt.Println(countryName) // Output: United States
Types ¶
type Location ¶
type Location struct {
Lat float64 // Latitude of the location.
Lon float64 // Longitude of the location.
City string // Name of the location (e.g., city name).
Admin1 string // First-level administrative division (e.g., state, province).
Admin2 string // Second-level administrative division (e.g., county, region).
CC string // Country Code (e.g., US, GB).
Country string // Name of the country
}
Location represents a geographical point with associated administrative data.
func FindLocation ¶
FindLocation is a convenience function to query the geocoder directly for a single coordinate. It returns a pointer to the nearest Location found, or nil if no location is found (e.g., input coordinate is invalid or no data is loaded). The 'verbose' parameter controls logging for the internal geocoder instance.
coordinate: [lat, lng]
Example usage:
location := geodecode.FindLocation([2]float64{34.0522, -118.2437}, false) // Los Angeles
if location != nil {
fmt.Printf("City: %s, Country: %s\n", location.City, location.Country)
}
type RGeocoder ¶
type RGeocoder struct {
// contains filtered or unexported fields
}
RGeocoder represents the main reverse geocoding service. It holds the KD-Tree and the loaded location data.
func GetRGeocoder ¶
GetRGeocoder returns a singleton instance of the reverse geocoder. The geocoder's data is loaded and the KD-Tree is built only once, on the first call to this function. The 'verbose' parameter controls whether detailed loading and warning messages are printed to the console.