Skip to content

Migrate from v0.1.20 to v1.0.x

Fabrizio Moscon edited this page Mar 15, 2015 · 2 revisions

Migration

Hopefully this contains some help for developers migrating to v1.0.0

Addition/clarification/contributions are most welcome!

Initialization

// v0.1.20 is exposing a singleton so there is no need for `new`
// as a consequence of the way require cache modules gm was behaving like a global object
var gm = require('googlemaps');

// v1.0.0 exports **ONLY** the constructor so you will **need** to use `new`
var gmAPI = new GoogleMapsAPI(config);

Configuration

// v0.1.20 allowed the user to specify the configuration after the requirement like so
var gm = require('googlemaps');
gm.config(key, value);

// v1.0.0 **ONLY** accepts a configuration object at creation time
var config = {
  'key': '<YOUR-KEY>',
  'google_client_id':   '<YOUR-CLIENT-ID>', //optional
  'stagger_time':       1000, //optional
  'encode_polylines':   false,
  'secure':             true, // use https
  'proxy':              'http://127.0.0.1:9999', // optional
  'google_private_key': '<YOUR-PRIVATE-KEY>' // to use maps for Work
};
var gmAPI = new GoogleMapsAPI(config);

Calling API functions

// API functions exposed on v0.1.20 accepted one or more arguments and in some cases the list was very long
var gm = require('googlemaps');
gm.config(key, value);
gm.reverseGeocode('41.850033,-87.6500523', function(err, data){
  util.puts(JSON.stringify(data));
});

// v1.0.0 **ONLY** accepts an object with multiple keys
var config = {
  'key': '<YOUR-KEY>',
  'google_client_id':   '<YOUR-CLIENT-ID>', //optional
  'stagger_time':       1000, //optional
  'encode_polylines':   false,
  'secure':             true, // use https
  'proxy':              'http://127.0.0.1:9999', // optional
  'google_private_key': '<YOUR-PRIVATE-KEY>' // to use maps for Work
};

var gmAPI = new GoogleMapsAPI(config);

var geocodeParams = {
  "address":    "121, Curtain Road, EC2A 3AD, London UK",
  "components": "components=country:GB",
  "bounds":     "55,-1|54,1",
  "language":   "en",
  "region":     "uk"
};

gmAPI.geocode(geocodeParams, function(err, result){
  console.log(result);
});
Clone this wiki locally