Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fegoa89/zipcodes
Zipcode geocoding and distance calculation using datasets from http://www.geonames.org/
https://github.com/fegoa89/zipcodes
geonames golang golang-package postal-code zipcodes
Last synced: 10 days ago
JSON representation
Zipcode geocoding and distance calculation using datasets from http://www.geonames.org/
- Host: GitHub
- URL: https://github.com/fegoa89/zipcodes
- Owner: fegoa89
- License: mit
- Created: 2019-04-10T09:10:34.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-13T19:36:04.000Z (over 1 year ago)
- Last Synced: 2024-06-20T16:51:34.700Z (5 months ago)
- Topics: geonames, golang, golang-package, postal-code, zipcodes
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 6
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zipcodes - Zip Code Lookups
A Zipcode lookup package that uses the GeoNames Postal Code dataset from http://www.geonames.org .
You can initialize it with a Postal Code dataset downloaded from http://download.geonames.org/export/zip .## Install
Install with
```sh
go get github.com/fegoa89/zipcodes
```### Initialize Struct
Initializes a zipcodes struct. It will throw an error if:
- The file does not exist / wrong format.
- Some of the lines contain less that 12 elements (in the readme.txt of each postal code dataset, they define up to 12 elements).
- Where latitude / longitude value are contains a wrong format (string that can not be converted to `float64`).```golang
zipcodesDataset, err := zipcodes.New("path/to/my/dataset.txt")
```### Lookup
Looks for a zipcode inside the map interface we loaded. If the object can not be found by the zipcode, it will return an error.
When a object is found, returns its zipcode, place name, administrative name, latitude and longitude:```golang
location, err := zipcodesDataset.Lookup("10395")
```### DistanceInKm
Returns the line of sight distance between two zipcodes in kilometers:```golang
location, err := zipcodesDataset.DistanceInKm("01945", "03058") // 49.87
```### DistanceInMiles
Returns the line of sight distance between two zipcodes in miles:```golang
location, err := zipcodesDataset.DistanceInMiles("01945", "03058") // 30.98
```### DistanceInKmToZipCode
Calculates the distance between a zipcode and a give lat/lon in Kilometers:```golang
location, err := zipcodesDataset.DistanceInKmToZipCode("01945", 51.4267, 13.9333) // 1.11
```### DistanceInMilToZipCode
Calculates the distance between a zipcode and a give lat/lon in Miles:```golang
location, err := zipcodesDataset.DistanceInMilToZipCode("01945", 51.4267, 13.9333) // 0.69
```### GetZipcodesWithinKmRadius
Returns a list of zipcodes within the radius of this zipcode in Kilometers:```golang
location, err := zipcodesDataset.GetZipcodesWithinKmRadius("01945", 50) // ["03058"]
```### GetZipcodesWithinMlRadius
Returns a list of zipcodes within the radius of this zipcode in Miles:```golang
location, err := zipcodesDataset.GetZipcodesWithinMlRadius("01945", 50) // ["03058"]
```