Giter Club home page Giter Club logo

geonames.js's Introduction

geonames.js

if you Need an API to fetch countries, states, regions, cities dynamically here's the library you're looking for

geonames.js is a flexible library for browser and Nodejs built on top geonames.org REST api

not found

1. Installation

npm install --save geonames.js


2. Requirements

You have to register (it's free) on Geonames.org in order to get the username that will be necessary for the api to work

3. Usage:

You can fetch almost anything taking advandage of the huge amount of information provided by geonames.org, It contains over 10 million geographical names and consists of over 9 million unique features whereof 2.8 million populated places and 5.5 million alternate names.

The list of available API is in here under the webservice column.

  • Nodejs: (bluebird promise based API)

    var Geonames = require('geonames.js');
    geonames = new Geonames({username: 'myusername', lan: 'en', encoding: 'JSON'});
    //plain call
    geonames.search({q: 'CONT'}) //get continents
    .then(function(resp){
      console.log(resp.geonames);
    })
    .catch(function(err){
    })
    //chaining calls
    geonames.countryInfo({}) 
    .then(function(countries){
      return geonames.children({geonameId: countries.geonames[0].geonameId})
    })
    .then(function(states){
      return geonames.children({geonameId: stateOrProvince.geonames[0].geonameId});
    })
    .then(function(regions){
      return geonames.children({geonameId: region.geonames[0].geonameId});
    })
    .then(function(cities){
      console.log(cities.geonames);
    })
    .catch(function(err){
    })
  • browser: (plain ajax xhr call)

import the script:

<script type="text/javascript" src="node_modules/geonames.js/dist/geonames.min.js"></script>
 //GeoNames constructor is attacched to the global object
geonames = new GeoNames({username: username, lan: 'en', encoding: 'JSON'});
geonames.search({q: 'CONT'}, function(continents){ //plain xhr call
  console.log(continents);
}, function(err){
  //error
})

4. Contribution:

Feel free to contribute, any help is really appreciated :)

run with:

gulp

gulp dist (for the minification)

USERNAME=myusername npm test (for unit testing with mocha)

5. License:

MIT License

Copyright (c) 2017 kinotto

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

geonames.js's People

Contributors

kinotto avatar

Watchers

Romain Oliva avatar

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.