Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added HERE geocoder #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ $ geocodify -r geocodify-nullisland -s nullisland test.csv
* Canada-Only
* Unforgiving address input format, see [service documentation](http://geogratis.gc.ca/site/eng/geoloc) for details.

`here`: [HERE Geocoder API](https://developer.here.com/documentation/geocoder/topics/what-is.html)

* Worldwide

## options

The input is either the first positional argument, like
Expand Down Expand Up @@ -73,7 +77,7 @@ Selecting `--output=geojson` encodes results as [GeoJSON](http://geojson.org/)

See **geocoders** above for details

--source={census,mapbox,mapquestopen,twofishes,geogratis}
--source={census,mapbox,mapquestopen,twofishes,geogratis,here}

## use

Expand Down
2 changes: 2 additions & 0 deletions geocodify.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var geocodify = require('./'),
argv = require('subarg')(process.argv.slice(2));

argv.mapbox_mapid = argv.mapbox_mapid || process.env.MAPBOX_MAPID;
argv.here_app_id = argv.here_app_id || process.env.HEREAPPID;
argv.here_app_code = argv.here_app_code || process.env.HEREAPPCODE;

var output = argv.f || argv.output || 'csv';
argv.source = argv.s || argv.source || 'mapbox';
Expand Down
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
var xtend = require('xtend'),
stream = require('stream'),
http = require('http'),
https = require('https'),
through = require('through2'),
concat = require('concat-stream');

var throttle = 1000;

var sources = {
here: function geocode(address, options, callback) {
https.get(geocodeUrl(address), function(res) {
res.pipe(concat(function(buf) {
var data = JSON.parse(buf);
if (data && data.Response) {
callback(null, {
lat: data.Response.View[0].Result[0].Location.DisplayPosition.Latitude,
lon: data.Response.View[0].Result[0].Location.DisplayPosition.Longitude
});
} else {
callback('no result');
}
}));
});
function geocodeUrl(address) {
return 'https://geocoder.api.here.com/6.2/geocode.json?app_id='+
options.here_app_id+'&app_code='+options.here_app_code+
"&searchtext="+encodeURIComponent(address);
}
},
mapbox: function geocode(address, options, callback) {
http.get(geocodeUrl(address), function(res) {
res.pipe(concat(function(buf) {
Expand Down