Skip to content

Commit

Permalink
Added HERE as a provider for geocoding and reverse geocoding
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaswc committed Nov 25, 2015
1 parent b346c1d commit b6287c9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The plugin supports many different data providers:
* [What3Words](http://http://what3words.com/)
* [Photon](http://photon.komoot.de/)
* [Mapzen Search](https://mapzen.com/projects/search)
* [HERE Geocoder API] (https://developer.here.com/rest-apis/documentation/geocoder/topics/overview.html)

The plugin can easily be extended to support other providers.

Expand Down
3 changes: 2 additions & 1 deletion bower.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"photon",
"what3words",
"mapquest",
"mapzen"
"mapzen",
"here"
],
"license": "BSD-2-Clause",
"ignore": [
Expand Down
5 changes: 3 additions & 2 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "leaflet-control-geocoder",
"version": "1.3.2",
"description": "Extendable geocoder with builtin support for Nominatim, Bing, Google, Mapbox, Photon, What3Words, MapQuest, Mapzen",
"description": "Extendable geocoder with builtin support for Nominatim, Bing, Google, Mapbox, Photon, What3Words, MapQuest, Mapzen, HERE",
"main": "src/index.js",
"scripts": {
"prepublish": "sh ./scripts/build.sh",
Expand All @@ -22,7 +22,8 @@
"photon",
"what3words",
"mapquest",
"mapzen"
"mapzen",
"here"
],
"author": "Per Liedman <[email protected]>",
"license": "BSD-2-Clause",
Expand Down
70 changes: 70 additions & 0 deletions src/geocoders/here.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
var L = require('leaflet'),
Util = require('../util');

module.exports = {
class: L.Class.extend({
options: {
geocodeUrl: 'http://geocoder.api.here.com/6.2/geocode.json',
reverseGeocodeUrl: 'http://reverse.geocoder.api.here.com/6.2/reversegeocode.json',
app_id: '<insert your app_id here>',
app_code: '<insert your app_code here>',
geocodingQueryParams: {},
reverseQueryParams: {}
},

initialize: function(options) {
L.setOptions(this, options);
},

geocode: function(query, cb, context) {
var params = {
searchtext: query,
gen: 9,
app_id: this.options.app_id,
app_code: this.options.app_code,
jsonattributes: 1
};
params = L.Util.extend(params, this.options.geocodingQueryParams);
this.getJSON(this.options.geocodeUrl, params, cb, context);
},

reverse: function(location, scale, cb, context) {
var params = {
prox: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng),
mode: 'retrieveAddresses',
app_id: this.options.app_id,
app_code: this.options.app_code,
gen: 9,
jsonattributes: 1
};
params = L.Util.extend(params, this.options.reverseQueryParams);
this.getJSON(this.options.reverseGeocodeUrl, params, cb, context);
},

getJSON: function(url, params, cb, context) {
Util.getJSON(url, params, function(data) {
var results = [],
loc,
latLng,
latLngBounds;
if (data.response.view && data.response.view.length) {
for (var i = 0; i <= data.response.view[0].result.length - 1; i++) {
loc = data.response.view[0].result[i].location;
latLng = L.latLng(loc.displayPosition.latitude, loc.displayPosition.longitude);
latLngBounds = L.latLngBounds(L.latLng(loc.mapView.topLeft.latitude, loc.mapView.topLeft.longitude), L.latLng(loc.mapView.bottomRight.latitude, loc.mapView.bottomRight.longitude));
results[i] = {
name: loc.address.label,
bbox: latLngBounds,
center: latLng
};
}
}
cb.call(context, results);
})
}
}),

factory: function(options) {
return new L.Control.Geocoder.HERE(options);
}
};
7 changes: 5 additions & 2 deletions src/index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var L = require('leaflet'),
What3Words = require('./geocoders/what3words'),
Google = require('./geocoders/google'),
Photon = require('./geocoders/photon'),
Mapzen = require('./geocoders/mapzen');
Mapzen = require('./geocoders/mapzen'),
HERE = require('./geocoders/here');

module.exports = L.Util.extend(Control.class, {
Nominatim: Nominatim.class,
Expand All @@ -25,7 +26,9 @@ module.exports = L.Util.extend(Control.class, {
Photon: Photon.class,
photon: Photon.factory,
Mapzen: Mapzen.class,
mapzen: Mapzen.factory
mapzen: Mapzen.factory,
HERE: HERE.class,
here: HERE.factory
});

L.Util.extend(L.Control, {
Expand Down

0 comments on commit b6287c9

Please sign in to comment.