GithubHelp home page GithubHelp logo

flpms / google-locations-es6 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eastbayjake/google-locations

2.0 3.0 3.0 57 KB

Address searches via Google Geocoding for the Google Places API with ES 6

License: MIT License

JavaScript 100.00%

google-locations-es6's Introduction

Google Locations - ES6 build status

This is a fork from a another fork. If you want know the original go to this node-google-places and/or if you want a no ES6 version go to google-locations.

REMEMBER: This is a ES6 version, in futher maybe I add other functions which made different from the original fork, for now this package only work with Node 4.

Google Places + Google Geocoding API module for node.js. Supports basic functions on the Google Places API -- search, autocomplete, and details -- as well as geocoding and reverse geocoding capabilities with the Google Geocoding API. It also contains two convenience methods, searchByAddress and searchByPhone, that allow users to retrieve Place details by address or phone number.

This module requires a valid Google API key and enabled access for Google Places and/or Google Geocoding. Check out the Google Places API docs or Google Geocoding API docs for more information. Please note that searchByAddress uses the Geocoding API and searchByPhone uses the /place/textsearch endpoint which counts as 10 requests toward your daily quota.

Install

npm install google-locations --save

Methods

search(options, callback)

This method makes requests to the /place/nearbysearch endpoint. Any supported query parameter/value for that endpoint is a valid key/value for the options object.

autocomplete(options, callback)

This method makes requests to the /place/autocomplete endpoint. Any supported query parameter/value for that endpoint is a valid key/value for the options object.

details(options, callback)

This method makes requests to the /place/details endpoint. It requires a placeid parameter, but any supported query parameter/value for that endpoint is a valid key/value for the options object.

searchByAddress(options, callback)

This method lets you query for Google Place details by address and location name. It is a convenience wrapper that geocodes an address, does a place search for matching names near that geocoordinate, then does follow-up detail requests for each result in search, up to a specified limit. The only mandatory parameter is address. If rankby is 'distance', name must be specified. If rankby is 'prominence', radius must be specified. If rankby is not specified, it will default to 'distance' and therefore name will be required. The most reliable practice is to specify both an address and name. The number of detail requests is limited by the 'maxResults' parameter: if maxResults isn't specified it will default to 1, but maxResults will automatically never be greater than the number of results returned by a search request.

searchByPhone(options, callback)

This method lets you query for Google Place details by phone number. 'phone' is a required parameter. If 'maxResults' isn't specified it will default to 1, only returning details about the top result in search. NOTE: This method uses the Google Places API's /place/textsearch endpoint, so each request counts as 10 requests toward your daily quota!

Usage

var GoogleLocations = require('google-locations');

var locations = new GoogleLocations('YOUR_API_KEY');

locations.search({keyword: 'Google', location: [37.42291810, -122.08542120]}, function(err, response) {
  console.log("search: ", response.results);

  locations.details({placeid: response.results[0].place_id}, function(err, response) {
    console.log("search details: ", response.result.name);
    // search details: Google
  });
});

locations.autocomplete({input: 'Verm', types: "(cities)"}, function(err, response) {
  console.log("autocomplete: ", response.predictions);

  var success = function(err, response) {
    console.log("did you mean: ", response.result.name);
    // did you mean:  Vermont
    // did you mean:  Vermont South
    // did you mean:  Vermilion
    // did you mean:  Vermillion
  };

  for(var index in response.predictions) {
    locations.details({placeid: response.predictions[index].place_id}, success);
  }
});

locations.searchByAddress({address: '1600 Amphitheatre Pkwy, Mountain View, CA', name: 'Goo', maxResults: 2, rankby: "prominence", radius: 5000}, function(err, response){
  for (var index in response.details) {
    console.log("Potential Match: " + response.details[index].name);
    // Potential Match: Google
    // Potential Match: Gooey Cookie Factory
  }
  for (var index in response.errors) {
    console.log("Error looking up place details: ", response.errors[index]);
  }
});

locations.searchByPhone({phone: "(650) 253-0000"}, maxResults: 2, function(err, response){
  // Returns up to 2 matches for this phone number
});

Test

To test simply install development dependencies and run:

vows test/* --spec

Planned for future versions

  • Configurable URI;
  • Change tests to Mocha;
  • Change callback to promises;
  • Add more features, if you want a feature, let we know by sending a PR or put in Issues;

google-locations-es6's People

Contributors

eastbayjake avatar flpms avatar jpowers avatar mheadd avatar shfx avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

giao tylersweeney

google-locations-es6's Issues

Bug fix

Create a bug fix to avoid error when google don't send results. Like occur in this branch.

erank3@6c10549

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.