From 517504290ee49cc606090d050a90f44e799d6030 Mon Sep 17 00:00:00 2001 From: Jack McBride Date: Fri, 13 May 2022 10:34:16 +0100 Subject: [PATCH] Accept zero value numbers for reverse geocoding --- index.js | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index 6b38146..7b8b002 100644 --- a/index.js +++ b/index.js @@ -10,24 +10,21 @@ * Version */ -var version = '0.2.3'; - +var version = "0.2.3"; /** * Geocoder */ -function Geocoder () { +function Geocoder() { this.selectProvider("google"); -}; +} /** * Geocoder prototype */ Geocoder.prototype = { - - /** * Selects a webservice provider * @@ -36,16 +33,14 @@ Geocoder.prototype = { * @api public */ - selectProvider: function ( name, opts ) { - - if ( ! name ) { - return cbk( new Error( "Geocoder.selectProvider requires a name.") ); + selectProvider: function (name, opts) { + if (!name) { + return cbk(new Error("Geocoder.selectProvider requires a name.")); } this.provider = name; this.providerOpts = opts || {}; - this.providerObj = require("./providers/"+name); - + this.providerObj = require("./providers/" + name); }, /** @@ -57,23 +52,28 @@ Geocoder.prototype = { * @api public */ - geocode: function ( loc, cbk, opts ) { - - if ( ! loc ) { - return cbk( new Error( "Geocoder.geocode requires a location.") ); + geocode: function (loc, cbk, opts) { + if (!loc) { + return cbk(new Error("Geocoder.geocode requires a location.")); } return this.providerObj.geocode(this.providerOpts, loc, cbk, opts); - }, - reverseGeocode: function ( lat, lng, cbk, opts ) { - if ( !lat || !lng ) { - return cbk( new Error( "Geocoder.reverseGeocode requires a latitude and longitude." ) ); + reverseGeocode: function (lat, lng, cbk, opts) { + if (isNan(lat) || isNan(lng)) { + return cbk( + new Error("Geocoder.reverseGeocode requires a latitude and longitude.") + ); } - return this.providerObj.reverseGeocode(this.providerOpts, lat, lng, cbk, opts ); - + return this.providerObj.reverseGeocode( + this.providerOpts, + lat, + lng, + cbk, + opts + ); }, /** @@ -82,8 +82,7 @@ Geocoder.prototype = { * @api public */ - version: version - + version: version, }; /**