diff --git a/providers/google.js b/providers/google.js index 0e2347a..2e221e4 100644 --- a/providers/google.js +++ b/providers/google.js @@ -1,29 +1,39 @@ var request = require("request"); -var _ = require('underscore'); +var _ = require("underscore"); -exports.geocode = function ( providerOpts, loc, cbk, opts ) { +exports.geocode = function (providerOpts, loc, cbk, opts) { - var options = _.extend({sensor: false, address: loc}, opts || {}); + var proto = "http:", + options = _.extend({sensor: false, address: loc}, opts || {}); - request({ - uri:"http://maps.googleapis.com/maps/api/geocode/json", - qs:options - }, function(err,resp,body) { - if (err) return cbk(err); - cbk(null,JSON.parse(body)); - }); + if (_.has(options, "key")) { + proto = "https:"; + } + + request({ + uri: proto + "//maps.googleapis.com/maps/api/geocode/json", + qs: options + }, function (err, resp, body) { + if (err) return cbk(err); + cbk(null, JSON.parse(body)); + }); }; -exports.reverseGeocode = function ( providerOpts, lat, lng, cbk, opts ) { +exports.reverseGeocode = function (providerOpts, lat, lng, cbk, opts) { + + var proto = "http:", + options = _.extend({sensor: false, latlng: lat + ',' + lng}, opts || {}); - var options = _.extend({sensor: false, latlng: lat + ',' + lng}, opts || {}); + if (_.has(options, "key")) { + proto = "https:"; + } - request({ - uri:"http://maps.googleapis.com/maps/api/geocode/json", - qs:options - }, function(err,resp,body) { - if (err) return cbk(err); - cbk(null,JSON.parse(body)); - }); + request({ + uri: proto + "//maps.googleapis.com/maps/api/geocode/json", + qs: options + }, function (err, resp, body) { + if (err) return cbk(err); + cbk(null, JSON.parse(body)); + }); -}; \ No newline at end of file +};