Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 187 lines (146 sloc) 7.243 kB
f7c69bc @fabriziomoscon fix Travis badge link [skip ci]
fabriziomoscon authored
1 [![Build Status](https://travis-ci.org/moshen/node-googlemaps.svg)](https://travis-ci.org/moshen/node-googlemaps)
09fab36 @fabriziomoscon adding TravisCI badge
fabriziomoscon authored
2
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
3 # Google Maps API for Node.js
90cfd79 @JoshSmith Finished Static Maps API and updated README
JoshSmith authored
4
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
5 This library implements the following Google Maps APIs, and can be also used by Google Maps for Work users.
6fc5da2 @moshen Changes to README
authored
6
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
7 * [Maps API Web Services](https://developers.google.com/maps/documentation/webservices/)
8 * [Google Places API](https://developers.google.com/places/)
9 * [Google Maps Image API](https://developers.google.com/maps/documentation/imageapis/)
cc81c0a @moshen Update README docs for the staticMap api
authored
10
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
11 This library is **NOT COMPATIBLE** with tags < `1.0.0`
cc81c0a @moshen Update README docs for the staticMap api
authored
12
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
13 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.
cc81c0a @moshen Update README docs for the staticMap api
authored
14
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
15 ### Installation
16
17 ```
18 npm install googlemaps
19 ```
20
21 ### What does it cover
22 [Maps API Web Services](https://developers.google.com/maps/documentation/webservices/):
23
24 * [Directions](https://developers.google.com/maps/documentation/directions/)
25 * [Distance matrix](https://developers.google.com/maps/documentation/distancematrix/)
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
26 * [Elevation](https://developers.google.com/maps/documentation/elevation/) - TO BE IMPROVED
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
27 * [Geocoding and reverse geocoding](https://developers.google.com/maps/documentation/geocoding)
28 * [Time zone](https://developers.google.com/maps/documentation/timezone) - NOT IMPLEMENTED YET
29
30 [Google Places API](https://developers.google.com/places/) - NOT COMPLETED
31
32 * [Place search](https://developers.google.com/places/documentation/search)
33 * [Place details](https://developers.google.com/places/documentation/details)
34
35 [Google Maps Image API](https://developers.google.com/maps/documentation/imageapis/)
36
247e2f2 @fabriziomoscon Refactor signature and implementation of staticMap API
fabriziomoscon authored
37 * [Static maps](https://developers.google.com/maps/documentation/staticmaps/)
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
38 * [Street view](https://developers.google.com/maps/documentation/streetview/) - TO BE IMPROVED
cc81c0a @moshen Update README docs for the staticMap api
authored
39
cb6ac89 @grobot Updated README to reflect the changes and use of config
grobot authored
40
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
41 ### Usage
cb6ac89 @grobot Updated README to reflect the changes and use of config
grobot authored
42
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
43 ```javascript
5f5e643 @fabriziomoscon Improve README
fabriziomoscon authored
44 var publicConfig = {
565aff4 @moshen Change config params to underscores to match api
authored
45 key: '<YOUR-KEY>',
46 stagger_time: 1000, // for elevationPath
47 encode_polylines: false,
48 secure: true, // use https
5f5e643 @fabriziomoscon Improve README
fabriziomoscon authored
49 proxy: 'http://127.0.0.1:9999' // optional, set a proxy for HTTP requests
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
50 };
5f5e643 @fabriziomoscon Improve README
fabriziomoscon authored
51 var gmAPI = new GoogleMapsAPI(publicConfig);
cb6ac89 @grobot Updated README to reflect the changes and use of config
grobot authored
52
5f5e643 @fabriziomoscon Improve README
fabriziomoscon authored
53 // or in case you are using Google Maps for Work
54 var enterpriseConfig = {
55 google_client_id: '<YOUR-CLIENT-ID>', // to use Google Maps for Work
56 google_private_key: '<YOUR-PRIVATE-KEY>', // to use Google Maps for Work
57 stagger_time: 1000, // for elevationPath
58 encode_polylines: false,
59 secure: true, // use https
60 proxy: 'http://127.0.0.1:9999' // optional, set a proxy for HTTP requests
61 };
62 var gmAPI = new GoogleMapsAPI(enterpriseConfig);
6e58c21 @grobot Added horizontal rule to readme and some white space.
grobot authored
63
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
64 // geocode API
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
65 var geocodeParams = {
66 "address": "121, Curtain Road, EC2A 3AD, London UK",
67 "components": "components=country:GB",
68 "bounds": "55,-1|54,1",
69 "language": "en",
70 "region": "uk"
71 };
6e58c21 @grobot Added horizontal rule to readme and some white space.
grobot authored
72
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
73 gmAPI.geocode(geocodeParams, function(err, result){
74 console.log(result);
75 });
6e58c21 @grobot Added horizontal rule to readme and some white space.
grobot authored
76
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
77 // reverse geocode API
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
78 var reverseGeocodeParams = {
79 "latlng": "51.1245,-0.0523",
80 "result_type": "postal_code",
81 "language": "en",
82 "location_type": "APPROXIMATE"
83 };
6e58c21 @grobot Added horizontal rule to readme and some white space.
grobot authored
84
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
85 gmAPI.reverseGeocode(reverseGeocodeParams, function(err, result){
86 console.log(result);
87 });
88 ```
cb6ac89 @grobot Updated README to reflect the changes and use of config
grobot authored
89
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
90 Check out the [unit tests](./tree/new-major-version/test/unit/) for more APIs examples.
cb6ac89 @grobot Updated README to reflect the changes and use of config
grobot authored
91
69ab811 @fabriziomoscon Refactor Streetview API
fabriziomoscon authored
92 ### Static Maps
93
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
94 ```javascript
95 var gmAPI = new GoogleMapsAPI();
b0c4151 @fabriziomoscon make callback not mandatory for staticMap
fabriziomoscon authored
96 var params = {
97 center: '444 W Main St Lock Haven PA',
98 zoom: 15,
99 size: '500x400',
100 maptype: 'roadmap',
101 markers: [
102 {
103 location: '300 W Main St Lock Haven, PA',
104 label : 'A',
105 color : 'green',
106 shadow : true
107 },
108 {
109 location: '444 W Main St Lock Haven, PA',
110 icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe%7C996600'
111 }
112 ],
113 style: [
114 {
115 feature: 'road',
116 element: 'all',
117 rules: {
118 hue: '0x00ff00'
119 }
120 }
121 ],
122 path: [
123 {
124 color: '0x0000ff',
125 weight: '5',
126 points: [
127 '41.139817,-77.454439',
128 '41.138621,-77.451596'
129 ]
130 }
131 ]
132 };
133 gmAPI.staticMap(params); // return static map URL
134 gmAPI.staticMap(params, function(err, binaryImage) {
135 // fetch asynchronously the binary image
136 });
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
137 ```
b0c4151 @fabriziomoscon make callback not mandatory for staticMap
fabriziomoscon authored
138 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"
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
139
140 By giving gm.staticMap an optional callback, you can retreive the static map PNG data:
141
142
143 You will get a map like:
144
b0c4151 @fabriziomoscon make callback not mandatory for staticMap
fabriziomoscon authored
145 ![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)
5d5eeb7 @moshen Created package.json for npm publishing
authored
146
69ab811 @fabriziomoscon Refactor Streetview API
fabriziomoscon authored
147 ### Street view
148
149 ```javascript
150 var gmAPI = new GoogleMapsAPI();
151 var params = {
76e0c68 @fabriziomoscon omit google_client_id
fabriziomoscon authored
152 location: '51.507868,-0.087689',
69ab811 @fabriziomoscon Refactor Streetview API
fabriziomoscon authored
153 size: '1200x1600',
76e0c68 @fabriziomoscon omit google_client_id
fabriziomoscon authored
154 heading: 108.4,
155 pitch: 7,
69ab811 @fabriziomoscon Refactor Streetview API
fabriziomoscon authored
156 fov: 40
157 };
158 var result = gmAPI.streetView(params);
159 ```
160
76e0c68 @fabriziomoscon omit google_client_id
fabriziomoscon authored
161 ![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)
69ab811 @fabriziomoscon Refactor Streetview API
fabriziomoscon authored
162
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
163 ### Further examples
5d5eeb7 @moshen Created package.json for npm publishing
authored
164
6a857d2 @moshen Fixed links to tests in README
authored
165 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.
6fc5da2 @moshen Changes to README
authored
166
fdd65cd @fabriziomoscon refactor and test encodePolylines
fabriziomoscon authored
167
168 ### Contributions
169 Criticism/Suggestions/Patches/PullRequests are welcome.
170
171
172 ### Original contributors list
5186fa8 @moshen README.md
authored
173
cec3ce9 @moshen Changed contributor links to gravatars in README
authored
174 [![evnm](https://secure.gravatar.com/avatar/2a8171b6c385b865e30bf070cf588329?s=50)](https://github.com/evnm)
175 [![duncanm](https://secure.gravatar.com/avatar/7310945bafb21aa68b18d61d8b9d2d61?s=50)](https://github.com/duncanm)
176 [![sugendran](https://secure.gravatar.com/avatar/3228aae57c1dc3f657bbc64c26c97b77?s=50)](https://github.com/sugendran)
177 [![JoshSmith](https://secure.gravatar.com/avatar/b07d5a5f2e75633b2085142250a6762b?s=50)](https://github.com/JoshSmith)
cb6ac89 @grobot Updated README to reflect the changes and use of config
grobot authored
178 [![grobot](https://secure.gravatar.com/avatar/ba3313effc329919b09bca67827bdf10?s=50)](https://github.com/grobot)
179 [![regality](https://secure.gravatar.com/avatar/fe513a9e239cebde58187721d67b7505?s=50)](https://github.com/regality)
180 [![spatical](https://secure.gravatar.com/avatar/a7c5765a4a4dfbf697f728bd75223641?s=50)](https://github.com/spatical)
5186fa8 @moshen README.md
authored
181
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
182 ### v1.0.0 maintener
b0c4151 @fabriziomoscon make callback not mandatory for staticMap
fabriziomoscon authored
183 [![moshen](https://avatars0.githubusercontent.com/u/168513?v=3&s=50)](https://github.com/moshen)
b25baa9 @fabriziomoscon add test for non singleton constructor
fabriziomoscon authored
184 [![fabriziomoscon](https://avatars1.githubusercontent.com/u/721890?v=3&u=b5079f5258887f4cc9a6de1cbadee230bca8ecc1&s=50)](https://github.com/fabriziomoscon)
185
b0c4151 @fabriziomoscon make callback not mandatory for staticMap
fabriziomoscon authored
186 Contributions and new issues are welcome!
Something went wrong with that request. Please try again.