Return generic result if reverse geocode fails

pull/54/merge
Candid Dauth 2016-10-19 11:56:06 +03:00
rodzic 8b61bdb55a
commit a4cdfcdba0
2 zmienionych plików z 23 dodań i 3 usunięć

Wyświetl plik

@ -4,6 +4,7 @@ var Promise = require("promise");
var cheerio = require("cheerio");
var zlib = require("zlib");
var compressjs = require("compressjs");
var utils = require("./utils");
request = request.defaults({
gzip: true,
@ -85,8 +86,18 @@ function find(query, loadUrls) {
+ "&zoom=" + (lonlat.zoom != null ? (lonlat.zoom >= 12 ? lonlat.zoom+2 : lonlat.zoom) : 17),
json: true
}).then(function(body) {
if(!body)
throw "Invalid response from name finder.";
if(!body || body) {
var name = utils.round(lonlat.lat, 5) + ", " + utils.round(lonlat.lon, 5);
return [ {
lat: lonlat.lat,
lon : lonlat.lon,
type : "coordinates",
short_name: name,
display_name : name,
zoom: lonlat.zoom != null ? lonlat.zoom : 15,
icon: "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png"
} ];
}
body.lat = lonlat.lat;
body.lon = lonlat.lon;
@ -105,6 +116,9 @@ function find(query, loadUrls) {
if(!body)
throw "Invalid response from name finder.";
if(body.error)
throw body.error;
return body.map(prepareSearchResult);
});
});

Wyświetl plik

@ -256,6 +256,11 @@ function isoDate(date) {
return pad(date.getUTCFullYear(), 4) + '-' + pad(date.getUTCMonth()+1, 2) + '-' + pad(date.getUTCDate(), 2) + 'T' + pad(date.getUTCHours(), 2) + ':' + pad(date.getUTCMinutes(), 2) + ':' + pad(date.getUTCSeconds(), 2) + 'Z';
}
function round(number, digits) {
var fac = Math.pow(10, digits);
return Math.round(number*fac)/fac;
}
module.exports = {
isInBbox : isInBbox,
filterStream : filterStream,
@ -267,5 +272,6 @@ module.exports = {
ArrayStream : ArrayStream,
streamEachPromise : streamEachPromise,
escapeXml : escapeXml,
isoDate : isoDate
isoDate : isoDate,
round: round
};