node-geocoder
Advanced tools
Comparing version 3.26.0 to 3.27.0
@@ -101,3 +101,3 @@ ## 3.0.0 | ||
- Fix production endpoint | ||
- Drop node 4 support | ||
- Drop node 4 and 6 support | ||
@@ -116,1 +116,6 @@ # 3.25.0 | ||
- Deprecate httpAdapters. | ||
# 3.27,0 | ||
- Update here geocoder to support `apiKey` | ||
- Allow passing of limit parameter to opendatafrance |
@@ -43,6 +43,6 @@ 'use strict'; | ||
/** | ||
* Reverse geocoding | ||
* @param {lat:<number>,lon:<number>} lat: Latitude, lon: Longitude | ||
* @param <function> callback Callback method | ||
*/ | ||
* Reverse geocoding | ||
* @param {lat:<number>,lon:<number>} lat: Latitude, lon: Longitude | ||
* @param <function> callback Callback method | ||
*/ | ||
AbstractGeocoder.prototype.reverse = function(query, callback) { | ||
@@ -57,10 +57,10 @@ if (typeof this._reverse != 'function') { | ||
/** | ||
* Geocode | ||
* @param <string> value Value to geocode | ||
* @param <function> callback Callback method | ||
*/ | ||
* Geocode | ||
* @param <string> value Value to geocode | ||
* @param <function> callback Callback method | ||
*/ | ||
AbstractGeocoder.prototype.geocode = function(value, callback) { | ||
var address = value | ||
var address = value; | ||
if (typeof value === 'object') { | ||
address = value.address | ||
address = value.address; | ||
} | ||
@@ -70,12 +70,27 @@ if (typeof this._geocode != 'function') { | ||
} | ||
if (net.isIPv4(address) && (!this.supportIPv4 || this.supportIPv4 == 'undefined')) { | ||
throw new ValueError(this.constructor.name + ' does not support geocoding IPv4'); | ||
if ( | ||
net.isIPv4(address) && | ||
(!this.supportIPv4 || this.supportIPv4 == 'undefined') | ||
) { | ||
throw new ValueError( | ||
this.constructor.name + ' does not support geocoding IPv4' | ||
); | ||
} | ||
if (net.isIPv6(address) && (!this.supportIPv6 || this.supportIPv6 == 'undefined')) { | ||
throw new ValueError(this.constructor.name + ' does not support geocoding IPv6'); | ||
if ( | ||
net.isIPv6(address) && | ||
(!this.supportIPv6 || this.supportIPv6 == 'undefined') | ||
) { | ||
throw new ValueError( | ||
this.constructor.name + ' does not support geocoding IPv6' | ||
); | ||
} | ||
if (this.supportAddress === false && (!net.isIPv4(address) && !net.isIPv6(address))) { | ||
throw new ValueError(this.constructor.name + ' does not support geocoding address'); | ||
if ( | ||
this.supportAddress === false && | ||
!net.isIPv4(address) && !net.isIPv6(address) | ||
) { | ||
throw new ValueError( | ||
this.constructor.name + ' does not support geocoding address' | ||
); | ||
} | ||
@@ -82,0 +97,0 @@ |
@@ -1,4 +0,14 @@ | ||
var util = require('util'), | ||
AbstractGeocoder = require('./abstractgeocoder'); | ||
const AbstractGeocoder = require('./abstractgeocoder'); | ||
const OPTIONS = [ | ||
'apiKey', | ||
'appId', | ||
'appCode', | ||
'language', | ||
'politicalView', | ||
'country', | ||
'state', | ||
'production' | ||
]; | ||
/** | ||
@@ -9,199 +19,208 @@ * Constructor | ||
*/ | ||
var HereGeocoder = function HereGeocoder(httpAdapter, options) { | ||
this.options = ['appId', 'appCode', 'language', 'politicalView', 'country', 'state', 'production']; | ||
class HereGeocoder extends AbstractGeocoder { | ||
constructor(httpAdapter, options) { | ||
super(httpAdapter, options); | ||
this.options = options; | ||
OPTIONS.forEach(option => { | ||
if (!options[option] || options[option] == 'undefined') { | ||
this.options[option] = null; | ||
} | ||
}); | ||
HereGeocoder.super_.call(this, httpAdapter, options); | ||
if (!this.options.appId || !this.options.appCode) { | ||
throw new Error('You must specify appId and appCode to use Here Geocoder'); | ||
} | ||
}; | ||
util.inherits(HereGeocoder, AbstractGeocoder); | ||
Object.defineProperties(HereGeocoder.prototype, { | ||
// Here geocoding API endpoint | ||
'_geocodeEndpoint': { | ||
get: function() { | ||
return this.options.production ? 'https://geocoder.api.here.com/6.2/geocode.json' : 'https://geocoder.cit.api.here.com/6.2/geocode.json'; | ||
// appId and appCode are deprecated | ||
if (!this.options.apiKey && !(this.options.appId && this.options.appCode)) { | ||
throw new Error('You must specify apiKey to use Here Geocoder'); | ||
} | ||
}, | ||
// Here reverse geocoding API endpoint | ||
'_reverseEndpoint': { | ||
get: function() { | ||
return this.options.production ? 'https://reverse.geocoder.api.here.com/6.2/reversegeocode.json' : 'https://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.json'; | ||
} | ||
} | ||
}) | ||
/** | ||
* Geocode | ||
* @param <string> value Value to geocode (Address) | ||
* @param <function> callback Callback method | ||
*/ | ||
HereGeocoder.prototype._geocode = function (value, callback) { | ||
/** | ||
* Geocode | ||
* @param <string> value Value to geocode (Address) | ||
* @param <function> callback Callback method | ||
*/ | ||
_geocode(value, callback) { | ||
var _this = this; | ||
var params = this._prepareQueryString(); | ||
var _this = this; | ||
var params = this._prepareQueryString(); | ||
if (value.address) { | ||
if (value.language) { | ||
if (value.address) { | ||
if (value.language) { | ||
params.language = value.language; | ||
} | ||
if (value.politicalView) { | ||
} | ||
if (value.politicalView) { | ||
params.politicalview = value.politicalView; | ||
} | ||
if (value.country) { | ||
} | ||
if (value.country) { | ||
params.country = value.country; | ||
if (value.state) { | ||
params.state = value.state; | ||
params.state = value.state; | ||
} else { | ||
delete params.state; | ||
delete params.state; | ||
} | ||
} | ||
if (value.zipcode) { | ||
} | ||
if (value.zipcode) { | ||
params.postalcode = value.zipcode; | ||
} | ||
params.searchtext = value.address; | ||
} else { | ||
params.searchtext = value; | ||
} | ||
params.searchtext = value.address; | ||
} else { | ||
params.searchtext = value; | ||
} | ||
this.httpAdapter.get(this._geocodeEndpoint, params, function (err, result) { | ||
var results = []; | ||
results.raw = result; | ||
this.httpAdapter.get(this._geocodeEndpoint, params, function(err, result) { | ||
var results = []; | ||
results.raw = result; | ||
if (err) { | ||
return callback(err, results); | ||
} else { | ||
var view = result.Response.View[0]; | ||
if (!view) { | ||
return callback(false, results); | ||
if (err) { | ||
return callback(err, results); | ||
} else { | ||
var view = result.Response.View[0]; | ||
if (!view) { | ||
return callback(false, results); | ||
} | ||
// Format each geocoding result | ||
results = view.Result.map(_this._formatResult); | ||
results.raw = result; | ||
callback(false, results); | ||
} | ||
}); | ||
} | ||
// Format each geocoding result | ||
results = view.Result.map(_this._formatResult); | ||
/** | ||
* Reverse geocoding | ||
* @param {lat:<number>,lon:<number>} lat: Latitude, lon: Longitude | ||
* @param <function> callback Callback method | ||
*/ | ||
_reverse(query, callback) { | ||
var lat = query.lat; | ||
var lng = query.lon; | ||
var _this = this; | ||
var params = this._prepareQueryString(); | ||
params.pos = lat + ',' + lng; | ||
params.mode = 'trackPosition'; | ||
this.httpAdapter.get(this._reverseEndpoint, params, function(err, result) { | ||
var results = []; | ||
results.raw = result; | ||
callback(false, results); | ||
} | ||
}); | ||
}; | ||
if (err) { | ||
return callback(err, results); | ||
} else { | ||
var view = result.Response.View[0]; | ||
if (!view) { | ||
return callback(false, results); | ||
} | ||
HereGeocoder.prototype._prepareQueryString = function () { | ||
var params = { | ||
'additionaldata': 'Country2,true', | ||
'gen': 8 | ||
}; | ||
// Format each geocoding result | ||
results = view.Result.map(_this._formatResult); | ||
results.raw = result; | ||
if (this.options.appId) { | ||
params.app_id = this.options.appId; | ||
callback(false, results); | ||
} | ||
}); | ||
} | ||
if (this.options.appCode) { | ||
params.app_code = this.options.appCode; | ||
} | ||
if (this.options.language) { | ||
params.language = this.options.language; | ||
} | ||
if (this.options.politicalView) { | ||
params.politicalview = this.options.politicalView; | ||
} | ||
if (this.options.country) { | ||
params.country = this.options.country; | ||
} | ||
if (this.options.state) { | ||
params.state = this.options.state; | ||
} | ||
return params; | ||
}; | ||
_formatResult(result) { | ||
var location = result.Location || {}; | ||
var address = location.Address || {}; | ||
var i; | ||
HereGeocoder.prototype._formatResult = function (result) { | ||
var location = result.Location || {}; | ||
var address = location.Address || {}; | ||
var i; | ||
var extractedObj = { | ||
formattedAddress: address.Label || null, | ||
latitude: location.DisplayPosition.Latitude, | ||
longitude: location.DisplayPosition.Longitude, | ||
country: null, | ||
countryCode: address.Country || null, | ||
state: address.State || null, | ||
county: address.County || null, | ||
city: address.City || null, | ||
zipcode: address.PostalCode || null, | ||
district: address.District || null, | ||
streetName: address.Street || null, | ||
streetNumber: address.HouseNumber || null, | ||
building: address.Building || null, | ||
extra: { | ||
herePlaceId: location.LocationId || null, | ||
confidence: result.Relevance || 0 | ||
}, | ||
administrativeLevels: {} | ||
}; | ||
var extractedObj = { | ||
formattedAddress: address.Label || null, | ||
latitude: location.DisplayPosition.Latitude, | ||
longitude: location.DisplayPosition.Longitude, | ||
country: null, | ||
countryCode: address.Country || null, | ||
state: address.State || null, | ||
county: address.County || null, | ||
city: address.City || null, | ||
zipcode: address.PostalCode || null, | ||
district: address.District || null, | ||
streetName: address.Street || null, | ||
streetNumber: address.HouseNumber || null, | ||
building: address.Building || null, | ||
extra: { | ||
herePlaceId: location.LocationId || null, | ||
confidence: result.Relevance || 0 | ||
}, | ||
administrativeLevels: {} | ||
}; | ||
for (i = 0; i < address.AdditionalData.length; i++) { | ||
var additionalData = address.AdditionalData[i]; | ||
switch (additionalData.key) { | ||
//Country 2-digit code | ||
case 'Country2': | ||
extractedObj.countryCode = additionalData.value; | ||
break; | ||
//Country name | ||
case 'CountryName': | ||
extractedObj.country = additionalData.value; | ||
break; | ||
//State name | ||
case 'StateName': | ||
extractedObj.administrativeLevels.level1long = additionalData.value; | ||
extractedObj.state = additionalData.value; | ||
break; | ||
//County name | ||
case 'CountyName': | ||
extractedObj.administrativeLevels.level2long = additionalData.value; | ||
extractedObj.county = additionalData.value; | ||
} | ||
} | ||
for (i = 0; i < address.AdditionalData.length; i++) { | ||
var additionalData = address.AdditionalData[i]; | ||
switch (additionalData.key) { | ||
//Country 2-digit code | ||
case 'Country2': | ||
extractedObj.countryCode = additionalData.value; | ||
break; | ||
//Country name | ||
case 'CountryName': | ||
extractedObj.country = additionalData.value; | ||
break; | ||
//State name | ||
case 'StateName': | ||
extractedObj.administrativeLevels.level1long = additionalData.value; | ||
extractedObj.state = additionalData.value; | ||
break; | ||
//County name | ||
case 'CountyName': | ||
extractedObj.administrativeLevels.level2long = additionalData.value; | ||
extractedObj.county = additionalData.value; | ||
} | ||
return extractedObj; | ||
} | ||
_prepareQueryString() { | ||
var params = { | ||
additionaldata: 'Country2,true', | ||
gen: 8 | ||
}; | ||
return extractedObj; | ||
}; | ||
// Deprecated | ||
if (this.options.appId) { | ||
params.app_id = this.options.appId; | ||
} | ||
// Deprecated | ||
if (this.options.appCode) { | ||
params.app_code = this.options.appCode; | ||
} | ||
/** | ||
* Reverse geocoding | ||
* @param {lat:<number>,lon:<number>} lat: Latitude, lon: Longitude | ||
* @param <function> callback Callback method | ||
*/ | ||
HereGeocoder.prototype._reverse = function (query, callback) { | ||
var lat = query.lat; | ||
var lng = query.lon; | ||
if (this.options.apiKey) { | ||
params.apiKey = this.options.apiKey; | ||
} | ||
if (this.options.language) { | ||
params.language = this.options.language; | ||
} | ||
if (this.options.politicalView) { | ||
params.politicalview = this.options.politicalView; | ||
} | ||
if (this.options.country) { | ||
params.country = this.options.country; | ||
} | ||
if (this.options.state) { | ||
params.state = this.options.state; | ||
} | ||
var _this = this; | ||
var params = this._prepareQueryString(); | ||
params.pos = lat + ',' + lng; | ||
params.mode = 'trackPosition'; | ||
return params; | ||
} | ||
} | ||
this.httpAdapter.get(this._reverseEndpoint, params, function (err, result) { | ||
var results = []; | ||
results.raw = result; | ||
Object.defineProperties(HereGeocoder.prototype, { | ||
// Here geocoding API endpoint | ||
_geocodeEndpoint: { | ||
get: function() { | ||
return 'https://geocoder.ls.hereapi.com/6.2/geocode.json'; | ||
} | ||
}, | ||
if (err) { | ||
return callback(err, results); | ||
} else { | ||
var view = result.Response.View[0]; | ||
if (!view) { | ||
return callback(false, results); | ||
} | ||
// Format each geocoding result | ||
results = view.Result.map(_this._formatResult); | ||
results.raw = result; | ||
callback(false, results); | ||
// Here reverse geocoding API endpoint | ||
_reverseEndpoint: { | ||
get: function() { | ||
return 'https://reverse.geocoder.ls.hereapi.com/6.2/reversegeocode.json'; | ||
} | ||
}); | ||
}; | ||
} | ||
}); | ||
module.exports = HereGeocoder; |
@@ -48,4 +48,6 @@ var util = require('util'), | ||
} | ||
if (value.limit) { | ||
params.limit = value.limit; | ||
} | ||
} | ||
this._forceParams(params); | ||
@@ -135,3 +137,2 @@ this.httpAdapter.get(this._endpoint, params, function(err, result) { | ||
} | ||
this._forceParams(params); | ||
@@ -183,6 +184,2 @@ this.httpAdapter.get(this._endpoint_reverse , params, function(err, result) { | ||
OpendataFranceGeocoder.prototype._forceParams = function(params){ | ||
params.limit = 20; | ||
}; | ||
module.exports = OpendataFranceGeocoder; |
@@ -74,2 +74,3 @@ 'use strict'; | ||
return new HereGeocoder(adapter, { | ||
apiKey: extra.apiKey, | ||
appId: extra.appId, | ||
@@ -76,0 +77,0 @@ appCode: extra.appCode, |
{ | ||
"name": "node-geocoder", | ||
"version": "3.26.0", | ||
"version": "3.27.0", | ||
"description": "Node Geocoder, node geocoding library, supports google maps, mapquest, open street map, tom tom, promise", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -106,3 +106,3 @@ # node-geocoder | ||
- `google` : GoogleGeocoder. Supports address geocoding and reverse geocoding. Use `options.clientId`and `options.apiKey`(privateKey) for business licence. You can also use `options.language` and `options.region` to specify language and region, respectively. | ||
- `here` : HereGeocoder. Supports address geocoding and reverse geocoding. You must specify `options.appId` and `options.appCode` with your license keys. Set `options.production` to `true` (default `false`) to use [HERE's production server environment](https://developer.here.com/documentation/geocoder/common/request-cit-environment-rest.html). You can also use `options.language`, `options.politicalView` ([read about political views here](https://developer.here.com/rest-apis/documentation/geocoder/topics/political-views.html)), `options.country`, and `options.state`. | ||
- `here` : HereGeocoder. Supports address geocoding and reverse geocoding. You must specify `options.apiKey` with your Here API key. You can also use `options.language`, `options.politicalView` ([read about political views here](https://developer.here.com/rest-apis/documentation/geocoder/topics/political-views.html)), `options.country`, and `options.state`. | ||
- `locationiq` : LocationIQGeocoder. Supports address geocoding and reverse geocoding just like openstreetmap but does require only a locationiq api key to be set. | ||
@@ -109,0 +109,0 @@ - For `geocode` you can use simple `q` parameter or an object containing th edifferent parameters defined here: http://locationiq.org/#docs |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2910
106942
39