node-geocoder
Advanced tools
Comparing version 3.18.0 to 3.19.0
@@ -230,1 +230,6 @@ # Changelog | ||
* Add PickPoint geocoder | ||
## 3.19.0 | ||
* Add formattedAddress to the open street map geocoder |
@@ -187,65 +187,68 @@ 'use strict'; | ||
for (var i = 0; i < result.address_components.length; i++) { | ||
var addressType = result.address_components[i].types[0]; | ||
switch (addressType) { | ||
//Country | ||
case 'country': | ||
extractedObj.country = result.address_components[i].long_name; | ||
extractedObj.countryCode = result.address_components[i].short_name; | ||
break; | ||
//Administrative Level 1 | ||
case 'administrative_area_level_1': | ||
extractedObj.administrativeLevels.level1long = result.address_components[i].long_name; | ||
extractedObj.administrativeLevels.level1short = result.address_components[i].short_name; | ||
break; | ||
//Administrative Level 2 | ||
case 'administrative_area_level_2': | ||
extractedObj.administrativeLevels.level2long = result.address_components[i].long_name; | ||
extractedObj.administrativeLevels.level2short = result.address_components[i].short_name; | ||
break; | ||
//Administrative Level 3 | ||
case 'administrative_area_level_3': | ||
extractedObj.administrativeLevels.level3long = result.address_components[i].long_name; | ||
extractedObj.administrativeLevels.level3short = result.address_components[i].short_name; | ||
break; | ||
//Administrative Level 4 | ||
case 'administrative_area_level_4': | ||
extractedObj.administrativeLevels.level4long = result.address_components[i].long_name; | ||
extractedObj.administrativeLevels.level4short = result.address_components[i].short_name; | ||
break; | ||
//Administrative Level 5 | ||
case 'administrative_area_level_5': | ||
extractedObj.administrativeLevels.level5long = result.address_components[i].long_name; | ||
extractedObj.administrativeLevels.level5short = result.address_components[i].short_name; | ||
break; | ||
// City | ||
case 'locality': | ||
extractedObj.city = result.address_components[i].long_name; | ||
break; | ||
// Address | ||
case 'postal_code': | ||
extractedObj.zipcode = result.address_components[i].long_name; | ||
break; | ||
case 'route': | ||
extractedObj.streetName = result.address_components[i].long_name; | ||
break; | ||
case 'street_number': | ||
extractedObj.streetNumber = result.address_components[i].long_name; | ||
break; | ||
case 'premise': | ||
extractedObj.extra.premise = result.address_components[i].long_name; | ||
break; | ||
case 'subpremise': | ||
extractedObj.extra.subpremise = result.address_components[i].long_name; | ||
break; | ||
case 'establishment': | ||
extractedObj.extra.establishment = result.address_components[i].long_name; | ||
break; | ||
case 'sublocality_level_1': | ||
case 'political': | ||
case 'sublocality': | ||
case 'neighborhood': | ||
if(!extractedObj.extra.neighborhood) { | ||
extractedObj.extra.neighborhood = result.address_components[i].long_name; | ||
} | ||
break; | ||
for (var x = 0; x < result.address_components[i].types.length; x++) { | ||
var addressType = result.address_components[i].types[x]; | ||
switch (addressType) { | ||
//Country | ||
case 'country': | ||
extractedObj.country = result.address_components[i].long_name; | ||
extractedObj.countryCode = result.address_components[i].short_name; | ||
break; | ||
//Administrative Level 1 | ||
case 'administrative_area_level_1': | ||
extractedObj.administrativeLevels.level1long = result.address_components[i].long_name; | ||
extractedObj.administrativeLevels.level1short = result.address_components[i].short_name; | ||
break; | ||
//Administrative Level 2 | ||
case 'administrative_area_level_2': | ||
extractedObj.administrativeLevels.level2long = result.address_components[i].long_name; | ||
extractedObj.administrativeLevels.level2short = result.address_components[i].short_name; | ||
break; | ||
//Administrative Level 3 | ||
case 'administrative_area_level_3': | ||
extractedObj.administrativeLevels.level3long = result.address_components[i].long_name; | ||
extractedObj.administrativeLevels.level3short = result.address_components[i].short_name; | ||
break; | ||
//Administrative Level 4 | ||
case 'administrative_area_level_4': | ||
extractedObj.administrativeLevels.level4long = result.address_components[i].long_name; | ||
extractedObj.administrativeLevels.level4short = result.address_components[i].short_name; | ||
break; | ||
//Administrative Level 5 | ||
case 'administrative_area_level_5': | ||
extractedObj.administrativeLevels.level5long = result.address_components[i].long_name; | ||
extractedObj.administrativeLevels.level5short = result.address_components[i].short_name; | ||
break; | ||
// City | ||
case 'locality': | ||
case 'postal_town': | ||
extractedObj.city = result.address_components[i].long_name; | ||
break; | ||
// Address | ||
case 'postal_code': | ||
extractedObj.zipcode = result.address_components[i].long_name; | ||
break; | ||
case 'route': | ||
extractedObj.streetName = result.address_components[i].long_name; | ||
break; | ||
case 'street_number': | ||
extractedObj.streetNumber = result.address_components[i].long_name; | ||
break; | ||
case 'premise': | ||
extractedObj.extra.premise = result.address_components[i].long_name; | ||
break; | ||
case 'subpremise': | ||
extractedObj.extra.subpremise = result.address_components[i].long_name; | ||
break; | ||
case 'establishment': | ||
extractedObj.extra.establishment = result.address_components[i].long_name; | ||
break; | ||
case 'sublocality_level_1': | ||
case 'political': | ||
case 'sublocality': | ||
case 'neighborhood': | ||
if(!extractedObj.extra.neighborhood) { | ||
extractedObj.extra.neighborhood = result.address_components[i].long_name; | ||
} | ||
break; | ||
} | ||
} | ||
@@ -252,0 +255,0 @@ } |
@@ -87,2 +87,3 @@ var util = require('util'), | ||
'longitude' : longitude, | ||
'formattedAddress': result.display_name, | ||
'country' : result.address.country, | ||
@@ -94,4 +95,4 @@ 'city' : result.address.city || result.address.town || result.address.village || result.address.hamlet, | ||
'streetNumber' : result.address.house_number, | ||
'countryCode' : countryCode | ||
'countryCode' : countryCode, | ||
'neighbourhood': result.address.neighbourhood || "" | ||
}; | ||
@@ -98,0 +99,0 @@ }; |
@@ -54,2 +54,40 @@ 'use strict'; | ||
function _processOptionsToParams(params, options){ | ||
//language (language_region, ex: `ru_RU`, `uk_UA`) | ||
if (options.language) { | ||
params.lang = options.language; | ||
} | ||
//results count (default 10) | ||
if (options.results) { | ||
params.results = options.results; | ||
} | ||
//skip count (default 0) | ||
if (options.skip) { | ||
params.skip = options.skip; | ||
} | ||
//Type of toponym (only for reverse geocoding) | ||
//could be `house`, `street`, `metro`, `district`, `locality` | ||
if (options.kind) { | ||
params.kind = options.kind; | ||
} | ||
//BBox (ex: `[[lat: 1.0, lng:2.0],[lat: 1.1, lng:2.2]]`) | ||
if (options.bbox) { | ||
if (options.bbox.length === 2){ | ||
params.kind = options.bbox[0].lng + ',' + options.bbox[0].lat; | ||
params.kind = params.kind + '~'; | ||
params.kind = params.kind + options.bbox[1].lng + ',' + options.bbox[1].lat; | ||
} | ||
} | ||
//Limit search in bbox (1) or not limit (0) | ||
if (options.rspn) { | ||
params.rspn = options.rspn; | ||
} | ||
} | ||
// Yandex geocoding API endpoint | ||
@@ -69,5 +107,3 @@ YandexGeocoder.prototype._endpoint = 'https://geocode-maps.yandex.ru/1.x/'; | ||
if (this.options.language) { | ||
params.lang = this.options.language; | ||
} | ||
_processOptionsToParams(params, this.options); | ||
@@ -90,2 +126,17 @@ this.httpAdapter.get(this._endpoint, params, function(err, result) { | ||
/** | ||
* Reverse geocoding | ||
* @param {lat:<number>,lon:<number>} lat: Latitude, lon: Longitude | ||
* @param <function> callback Callback method | ||
*/ | ||
YandexGeocoder.prototype._reverse = function (query, callback) { | ||
var lat = query.lat; | ||
var lng = query.lon; | ||
var value = lng + ',' + lat; | ||
this._geocode(value, callback); | ||
}; | ||
module.exports = YandexGeocoder; |
@@ -91,3 +91,10 @@ 'use strict'; | ||
if (geocoderName === 'yandex') { | ||
return new YandexGeocoder(adapter, {language: extra.language}); | ||
return new YandexGeocoder(adapter, { | ||
language: extra.language, | ||
results: extra.results, | ||
skip: extra.skip, | ||
kind: extra.kind, | ||
bbox: extra.bbox, | ||
rspn: extra.rspn | ||
}); | ||
} | ||
@@ -94,0 +101,0 @@ if (geocoderName === 'geocodio') { |
{ | ||
"name": "node-geocoder", | ||
"version": "3.18.0", | ||
"version": "3.19.0", | ||
"description": "Node Geocoder, node geocoding library, supports google maps, mapquest, open street map, tom tom, promise", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
20
test.js
@@ -1,6 +0,16 @@ | ||
const geocoder = require('./index')({ | ||
httpAdapter: 'request', | ||
provider: 'google', | ||
apiKey: 'TEST' | ||
}).geocode('29 rue chevreul').then(console.log); | ||
const NodeGeocoder = require('./index'); | ||
var geocoder = NodeGeocoder({ | ||
provider: 'google', | ||
language: 'es' | ||
}); | ||
geocoder.geocode({ | ||
address: "12, rue de l’École de Médecine" | ||
}).then(function(res) { | ||
console.log("res: ", res); | ||
}) | ||
.catch(function(err) { | ||
console.log("err: ", err); | ||
}); | ||
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
101567
2676