Giter Site home page Giter Site logo

node-googlemaps's Introduction

Build Status

Google Maps API for Node.js

A simple way to query the Google Maps API from Node.js

This has become a fairly complete api. Criticism/Suggestions/Patches/PullReq's welcome.

Installation

Installing npm (node package manager)

curl https://npmjs.org/install.sh | sh

Installing googlemaps

npm install googlemaps

Status

APIs implemented:

TODO:

Usage

var gm = require('googlemaps');
var util = require('util');

gm.reverseGeocode('41.850033,-87.6500523', function(err, data){
  util.puts(JSON.stringify(data));
});

gm.reverseGeocode(gm.checkAndConvertPoint([41.850033, -87.6500523]), function(err, data){
  util.puts(JSON.stringify(data));
});

Both examples print: {"status":"OK","results":[{"types":["postal_code"],"formatted_address":"Chicago, IL 60695, USA"...

For the Static Maps API, you can pass in all the required parameters as well as markers, styles, and paths using the formats outlined below.

markers = [
	{ 'location': '300 W Main St Lock Haven, PA' },
	{ 'location': '444 W Main St Lock Haven, PA',
		'color': 'red',
		'label': 'A',
		'shadow': 'false',
		'icon' : 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe%7C996600'
	}
]

styles = [
	{ 'feature': 'road', 'element': 'all', 'rules': 
		{ 'hue': '0x00ff00' }
	}
]

paths = [
	{ 'color': '0x0000ff', 'weight': '5', 'points': 
		[ '41.139817,-77.454439', '41.138621,-77.451596' ]
	}
]

util.puts(gm.staticMap('444 W Main St Lock Haven PA', 15, '500x400', false, false, 'roadmap', markers, styles, paths));

This example prints the URL for the Static Map image: "http://maps.googleapis.com/maps/api/staticmap?center=444%20W%20Main%20St%20Lock%20Haven%20PA&zoom=15&size=500x400&maptype=roadmap&markers=%7C300%20W%20Main%20St%20Lock%20Haven%2C%20PA&markers=%7Ccolor%3Ared%7Clabel%3AA%7Cicon%3Ahttp%3A%2F%2Fchart.apis.google.com%2Fchart%3Fchst%3Dd_map_pin_icon%26chld%3Dcafe%257C996600%7Cshadow%3Afalse%7C444%20W%20Main%20St%20Lock%20Haven%2C%20PA&style=%7Cfeature%3Aroad%7Celement%3Aall%7Chue%3A0x00ff00&path=weight%3A5%7Ccolor%3A0x0000ff%7C41.139817%2C-77.454439%7C41.138621%2C-77.451596&sensor=false"

By giving gm.staticMap an optional callback, you can retreive the static map PNG data:

util.puts(gm.staticMap('444 W Main St Lock Haven PA', 15, '500x400', function(err, data){
  require('fs').writeFileSync('test_map.png', data, 'binary');
}, false, 'roadmap', markers, styles, paths));

You will get a map like:

Some Map

Configuration

To set the configuration you call gm.config(key, value) or gm.config({key: value, .....})

Useful Configuration Options

proxy - set a proxy for http requests

stagger-time - defaults to 200ms - stagger async call times when multiple requests are required

encode-polylines - defaults to true - encodes polylines to the shorter Google format.

google-client-id - used for setting business specific parameters

google-private-key- used for setting business specific parameters


All the googlemaps functions follow this scheme: function(required, callback, optional)

All callbacks are expected to follow: function(error, results) Where the error returned is an Error object.

Please refer to the code, tests and the Google Maps API docs for further usage information.

Contributors

evnm duncanm sugendran JoshSmith grobot regality spatical

node-googlemaps's People

Contributors

aemkei avatar brandonwamboldt avatar evnm avatar fabriziomoscon avatar glesage avatar grobot avatar joshsmith avatar kodextor avatar marsup avatar moshen avatar onthestairs avatar regality avatar sayotuke avatar spatical avatar

Watchers

 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.