googlemaps
Advanced tools
Comparing version 0.1.20 to 1.0.0
{ | ||
"name": "googlemaps", | ||
"version": "0.1.20", | ||
"main": "./lib/googlemaps", | ||
"version": "1.0.0", | ||
"main": "lib/index", | ||
"description": "A simple way to query the Google Maps API from Node.js", | ||
@@ -22,3 +22,5 @@ "author": { | ||
"devDependencies": { | ||
"vows": "*" | ||
"vows": "~0.7.0", | ||
"mocha": "~1.21.4", | ||
"should": "~4.0.4" | ||
}, | ||
@@ -29,8 +31,11 @@ "engines": { | ||
"dependencies": { | ||
"request": "~2.2.9", | ||
"check-types": "~1.3.2", | ||
"request": "~2.44.0", | ||
"waitress": ">=0.0.2" | ||
}, | ||
"scripts": { | ||
"test": "NODE_ENV=test vows test/*.js --spec" | ||
"all-tests": "./node_modules/.bin/mocha test/unit && ./node_modules/.bin/vows test/integration/*.js --spec", | ||
"test": "./node_modules/.bin/mocha test/unit", | ||
"integration-test": "./node_modules/.bin/vows test/integration/*.js --spec" | ||
} | ||
} |
208
README.md
[![Build Status](https://travis-ci.org/moshen/node-googlemaps.svg)](https://travis-ci.org/moshen/node-googlemaps) | ||
# 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. | ||
This library implements the following Google Maps APIs, and can be also used by Google Maps for Work users. | ||
# Installation | ||
### Installing npm (node package manager) | ||
* [Maps API Web Services](https://developers.google.com/maps/documentation/webservices/) | ||
* [Google Places API](https://developers.google.com/places/) | ||
* [Google Maps Image API](https://developers.google.com/maps/documentation/imageapis/) | ||
curl https://npmjs.org/install.sh | sh | ||
This library is **NOT COMPATIBLE** with tags < `1.0.0` | ||
### Installing googlemaps | ||
If you want to migrate from a version older than `1.0.0` check the [WIKI](https://github.com/moshen/node-googlemaps/wiki/Migrate-from-v0.1.20-to-v1.0.x) for instructions. | ||
npm install googlemaps | ||
### Installation | ||
# Status | ||
APIs implemented: | ||
``` | ||
npm install googlemaps | ||
``` | ||
* [Geocoding](http://code.google.com/apis/maps/documentation/geocoding/) | ||
* [Directions](http://code.google.com/apis/maps/documentation/directions/) | ||
* [Elevation](http://code.google.com/apis/maps/documentation/elevation/) | ||
* [Places](http://code.google.com/apis/maps/documentation/places/) | ||
* [Place Details](https://code.google.com/apis/maps/documentation/places/#PlaceDetails) | ||
* [Distance Matrix](http://code.google.com/apis/maps/documentation/distancematrix/) | ||
* [Static Maps](http://code.google.com/apis/maps/documentation/staticmaps/) | ||
* [Street View](http://code.google.com/apis/maps/documentation/streetview/) | ||
### What does it cover | ||
[Maps API Web Services](https://developers.google.com/maps/documentation/webservices/): | ||
TODO: | ||
* [Directions](https://developers.google.com/maps/documentation/directions/) | ||
* [Distance matrix](https://developers.google.com/maps/documentation/distancematrix/) | ||
* [Elevation](https://developers.google.com/maps/documentation/elevation/) - TO BE IMPROVED | ||
* [Geocoding and reverse geocoding](https://developers.google.com/maps/documentation/geocoding) | ||
* [Time zone](https://developers.google.com/maps/documentation/timezone) - NOT IMPLEMENTED YET | ||
* [Tests for everything](http://github.com/moshen/node-googlemaps/tree/master/test/) (using [vows](http://vowsjs.org/)) | ||
[Google Places API](https://developers.google.com/places/) - NOT COMPLETED | ||
# Usage | ||
var gm = require('googlemaps'); | ||
var util = require('util'); | ||
* [Place search](https://developers.google.com/places/documentation/search) | ||
* [Place details](https://developers.google.com/places/documentation/details) | ||
gm.reverseGeocode('41.850033,-87.6500523', function(err, data){ | ||
util.puts(JSON.stringify(data)); | ||
}); | ||
[Google Maps Image API](https://developers.google.com/maps/documentation/imageapis/) | ||
gm.reverseGeocode(gm.checkAndConvertPoint([41.850033, -87.6500523]), function(err, data){ | ||
util.puts(JSON.stringify(data)); | ||
}); | ||
* [Static maps](https://developers.google.com/maps/documentation/staticmaps/) | ||
* [Street view](https://developers.google.com/maps/documentation/streetview/) - TO BE IMPROVED | ||
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' } | ||
} | ||
] | ||
### Usage | ||
paths = [ | ||
{ 'color': '0x0000ff', 'weight': '5', 'points': | ||
[ '41.139817,-77.454439', '41.138621,-77.451596' ] | ||
} | ||
] | ||
```javascript | ||
var config = { | ||
key: '<YOUR-KEY>', | ||
google_client_id: '<YOUR-CLIENT-ID>', //optional | ||
stagger_time: 1000, // for elevationPath | ||
encode_polylines: false, | ||
secure: true, // use https | ||
proxy: 'http://127.0.0.1:9999', // optional, set a proxy for HTTP requests | ||
google_private_key: '<YOUR-PRIVATE-KEY>' // to use Google Maps for Work | ||
}; | ||
util.puts(gm.staticMap('444 W Main St Lock Haven PA', 15, '500x400', false, false, 'roadmap', markers, styles, paths)); | ||
var gmAPI = new GoogleMapsAPI(config); | ||
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" | ||
// geocode API | ||
var geocodeParams = { | ||
"address": "121, Curtain Road, EC2A 3AD, London UK", | ||
"components": "components=country:GB", | ||
"bounds": "55,-1|54,1", | ||
"language": "en", | ||
"region": "uk" | ||
}; | ||
By giving gm.staticMap an optional callback, you can retreive the static map PNG data: | ||
gmAPI.geocode(geocodeParams, function(err, result){ | ||
console.log(result); | ||
}); | ||
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)); | ||
// reverse geocode API | ||
var reverseGeocodeParams = { | ||
"latlng": "51.1245,-0.0523", | ||
"result_type": "postal_code", | ||
"language": "en", | ||
"location_type": "APPROXIMATE" | ||
}; | ||
You will get a map like: | ||
gmAPI.reverseGeocode(reverseGeocodeParams, function(err, result){ | ||
console.log(result); | ||
}); | ||
``` | ||
![Some Map](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) | ||
Check out the [unit tests](./tree/new-major-version/test/unit/) for more APIs examples. | ||
# Configuration | ||
### Static Maps | ||
To set the configuration you call `gm.config(key, value)` or `gm.config({key: value, .....})` | ||
```javascript | ||
var gmAPI = new GoogleMapsAPI(); | ||
var params = { | ||
center: '444 W Main St Lock Haven PA', | ||
zoom: 15, | ||
size: '500x400', | ||
maptype: 'roadmap', | ||
markers: [ | ||
{ | ||
location: '300 W Main St Lock Haven, PA', | ||
label : 'A', | ||
color : 'green', | ||
shadow : true | ||
}, | ||
{ | ||
location: '444 W Main St Lock Haven, PA', | ||
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe%7C996600' | ||
} | ||
], | ||
style: [ | ||
{ | ||
feature: 'road', | ||
element: 'all', | ||
rules: { | ||
hue: '0x00ff00' | ||
} | ||
} | ||
], | ||
path: [ | ||
{ | ||
color: '0x0000ff', | ||
weight: '5', | ||
points: [ | ||
'41.139817,-77.454439', | ||
'41.138621,-77.451596' | ||
] | ||
} | ||
] | ||
}; | ||
gmAPI.staticMap(params); // return static map URL | ||
gmAPI.staticMap(params, function(err, binaryImage) { | ||
// fetch asynchronously the binary image | ||
}); | ||
``` | ||
This example prints the URL for the Static Map image: "https://maps.googleapis.com/maps/api/staticmap?center=444%20W%20Main%20St%20Lock%20Haven%20PA&zoom=15&size=500x400&maptype=roadmap&markers=color%3Agreen%7Clabel%3AA%7Cshadow%3Atrue%7C300%20W%20Main%20St%20Lock%20Haven%2C%20PA&markers=icon%3Ahttp%3A%2F%2Fchart.apis.google.com%2Fchart%3Fchst%3Dd_map_pin_icon%26chld%3Dcafe%257C996600%7C444%20W%20Main%20St%20Lock%20Haven%2C%20PA&path=weight%3A5%7Ccolor%3A0x0000ff%7Cenc%3A%7BbbzFfyvwMnFwP&style=feature%3Aroad%7Celement%3Aall%7Chue%3A0x00ff00" | ||
### Useful Configuration Options | ||
By giving gm.staticMap an optional callback, you can retreive the static map PNG data: | ||
`proxy` - set a proxy for http requests | ||
`stagger-time` - defaults to 200ms - stagger async call times when multiple requests are required | ||
You will get a map like: | ||
`encode-polylines` - defaults to true - encodes polylines to the shorter Google format. | ||
![Some Map](https://maps.googleapis.com/maps/api/staticmap?center=444%20W%20Main%20St%20Lock%20Haven%20PA&zoom=15&size=500x400&maptype=roadmap&markers=color%3Agreen%7Clabel%3AA%7Cshadow%3Atrue%7C300%20W%20Main%20St%20Lock%20Haven%2C%20PA&markers=icon%3Ahttp%3A%2F%2Fchart.apis.google.com%2Fchart%3Fchst%3Dd_map_pin_icon%26chld%3Dcafe%257C996600%7C444%20W%20Main%20St%20Lock%20Haven%2C%20PA&path=weight%3A5%7Ccolor%3A0x0000ff%7Cenc%3A%7BbbzFfyvwMnFwP&style=feature%3Aroad%7Celement%3Aall%7Chue%3A0x00ff00) | ||
`google-client-id` - used for setting business specific parameters | ||
### Street view | ||
`google-private-key`- used for setting business specific parameters | ||
```javascript | ||
var gmAPI = new GoogleMapsAPI(); | ||
var params = { | ||
location: '51.507868,-0.087689', | ||
size: '1200x1600', | ||
heading: 108.4, | ||
pitch: 7, | ||
fov: 40 | ||
}; | ||
var result = gmAPI.streetView(params); | ||
``` | ||
------------- | ||
![London - Tower Bridge from London Bridge](https://maps.googleapis.com/maps/api/streetview?location=51.507868,-0.087689&size=1200x1600&heading=108.4&fov=40&pitch=7) | ||
All the googlemaps functions follow this scheme: | ||
function(required, callback, optional) | ||
### Further examples | ||
All callbacks are expected to follow: | ||
function(error, results) | ||
Where the error returned is an Error object. | ||
Please refer to the code, [tests](http://github.com/moshen/node-googlemaps/tree/master/test/) and the [Google Maps API docs](http://code.google.com/apis/maps/documentation/webservices/index.html) for further usage information. | ||
# Contributors | ||
### Contributions | ||
Criticism/Suggestions/Patches/PullRequests are welcome. | ||
### Original contributors list | ||
[![evnm](https://secure.gravatar.com/avatar/2a8171b6c385b865e30bf070cf588329?s=50)](https://github.com/evnm) | ||
@@ -123,1 +174,6 @@ [![duncanm](https://secure.gravatar.com/avatar/7310945bafb21aa68b18d61d8b9d2d61?s=50)](https://github.com/duncanm) | ||
### v1.0.0 maintener | ||
[![moshen](https://avatars0.githubusercontent.com/u/168513?v=3&s=50)](https://github.com/moshen) | ||
[![fabriziomoscon](https://avatars1.githubusercontent.com/u/721890?v=3&u=b5079f5258887f4cc9a6de1cbadee230bca8ecc1&s=50)](https://github.com/fabriziomoscon) | ||
Contributions and new issues are welcome! |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
48590
23
1115
1
179
3
3
1
+ Addedcheck-types@~1.3.2
+ Addedasn1@0.1.11(transitive)
+ Addedassert-plus@0.1.5(transitive)
+ Addedasync@0.9.2(transitive)
+ Addedaws-sign2@0.5.0(transitive)
+ Addedbl@0.9.5(transitive)
+ Addedboom@0.4.2(transitive)
+ Addedcaseless@0.6.0(transitive)
+ Addedcheck-types@1.3.2(transitive)
+ Addedcombined-stream@0.0.7(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcryptiles@0.2.2(transitive)
+ Addedctype@0.5.3(transitive)
+ Addeddelayed-stream@0.0.5(transitive)
+ Addedforever-agent@0.5.2(transitive)
+ Addedform-data@0.1.4(transitive)
+ Addedhawk@1.1.1(transitive)
+ Addedhoek@0.9.1(transitive)
+ Addedhttp-signature@0.10.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedmime@1.2.11(transitive)
+ Addedmime-types@1.0.2(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.4.0(transitive)
+ Addedqs@1.2.2(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedrequest@2.44.0(transitive)
+ Addedsntp@0.2.4(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedtldts@6.1.61(transitive)
+ Addedtldts-core@6.1.61(transitive)
+ Addedtough-cookie@5.0.0(transitive)
+ Addedtunnel-agent@0.4.3(transitive)
- Removedrequest@2.2.9(transitive)
Updatedrequest@~2.44.0