Git Product home page Git Product logo

zipcodes's Introduction

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

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).
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:

location, err := zipcodesDataset.Lookup("10395")

DistanceInKm

Returns the line of sight distance between two zipcodes in kilometers:

location, err := zipcodesDataset.DistanceInKm("01945", "03058") // 49.87

DistanceInMiles

Returns the line of sight distance between two zipcodes in miles:

location, err := zipcodesDataset.DistanceInMiles("01945", "03058") // 30.98

DistanceInKmToZipCode

Calculates the distance between a zipcode and a give lat/lon in Kilometers:

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:

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:

location, err := zipcodesDataset.GetZipcodesWithinKmRadius("01945", 50) // ["03058"]

GetZipcodesWithinMlRadius

Returns a list of zipcodes within the radius of this zipcode in Miles:

location, err := zipcodesDataset.GetZipcodesWithinMlRadius("01945", 50) // ["03058"]

zipcodes's People

Contributors

fegoa89 avatar fgonzalezaguilera avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

zipcodes's Issues

Can I add 2-character state support?

The datasets have the state abbreviation but this module doesn't pull it in. Before I make the PR, since this repo hasn't been touched in awhile, I wanted to know if there's a chance it would be accepted.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.