Skip to content

Commit c1ead89

Browse files
davidpiesseperliedman
authored andcommitted
Updated for v2 of w3w API (#131)
1 parent cb06d69 commit c1ead89

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/geocoders/what3words.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var L = require('leaflet'),
44
module.exports = {
55
class: L.Class.extend({
66
options: {
7-
serviceUrl: 'http://api.what3words.com/'
7+
serviceUrl: 'https://api.what3words.com/v2/'
88
},
99

1010
initialize: function(accessToken) {
@@ -13,17 +13,16 @@ module.exports = {
1313

1414
geocode: function(query, cb, context) {
1515
//get three words and make a dot based string
16-
Util.getJSON(this.options.serviceUrl +'w3w', {
16+
Util.getJSON(this.options.serviceUrl +'forward', {
1717
key: this._accessToken,
18-
string: query.split(/\s+/).join('.'),
18+
addr: query.split(/\s+/).join('.'),
1919
}, function(data) {
2020
var results = [], loc, latLng, latLngBounds;
21-
if (data.position && data.position.length) {
22-
loc = data.words;
23-
latLng = L.latLng(data.position[0],data.position[1]);
21+
if (data.hasOwnProperty('geometry')) {
22+
latLng = L.latLng(data.geometry['lat'],data.geometry['lng']);
2423
latLngBounds = L.latLngBounds(latLng, latLng);
2524
results[0] = {
26-
name: loc.join('.'),
25+
name: data.words,
2726
bbox: latLngBounds,
2827
center: latLng
2928
};
@@ -38,17 +37,16 @@ module.exports = {
3837
},
3938

4039
reverse: function(location, scale, cb, context) {
41-
Util.getJSON(this.options.serviceUrl +'position', {
40+
Util.getJSON(this.options.serviceUrl +'reverse', {
4241
key: this._accessToken,
43-
position: [location.lat,location.lng].join(',')
42+
coords: [location.lat,location.lng].join(',')
4443
}, function(data) {
4544
var results = [],loc,latLng,latLngBounds;
46-
if (data.position && data.position.length) {
47-
loc = data.words;
48-
latLng = L.latLng(data.position[0],data.position[1]);
45+
if (data.status.status == 200) {
46+
latLng = L.latLng(data.geometry['lat'],data.geometry['lng']);
4947
latLngBounds = L.latLngBounds(latLng, latLng);
5048
results[0] = {
51-
name: loc.join('.'),
49+
name: data.words,
5250
bbox: latLngBounds,
5351
center: latLng
5452
};

0 commit comments

Comments
 (0)