@@ -4,7 +4,7 @@ var L = require('leaflet'),
4
4
module . exports = {
5
5
class : L . Class . extend ( {
6
6
options : {
7
- serviceUrl : 'http ://api.what3words.com/'
7
+ serviceUrl : 'https ://api.what3words.com/v2 /'
8
8
} ,
9
9
10
10
initialize : function ( accessToken ) {
@@ -13,17 +13,16 @@ module.exports = {
13
13
14
14
geocode : function ( query , cb , context ) {
15
15
//get three words and make a dot based string
16
- Util . getJSON ( this . options . serviceUrl + 'w3w ' , {
16
+ Util . getJSON ( this . options . serviceUrl + 'forward ' , {
17
17
key : this . _accessToken ,
18
- string : query . split ( / \s + / ) . join ( '.' ) ,
18
+ addr : query . split ( / \s + / ) . join ( '.' ) ,
19
19
} , function ( data ) {
20
20
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' ] ) ;
24
23
latLngBounds = L . latLngBounds ( latLng , latLng ) ;
25
24
results [ 0 ] = {
26
- name : loc . join ( '.' ) ,
25
+ name : data . words ,
27
26
bbox : latLngBounds ,
28
27
center : latLng
29
28
} ;
@@ -38,17 +37,16 @@ module.exports = {
38
37
} ,
39
38
40
39
reverse : function ( location , scale , cb , context ) {
41
- Util . getJSON ( this . options . serviceUrl + 'position ' , {
40
+ Util . getJSON ( this . options . serviceUrl + 'reverse ' , {
42
41
key : this . _accessToken ,
43
- position : [ location . lat , location . lng ] . join ( ',' )
42
+ coords : [ location . lat , location . lng ] . join ( ',' )
44
43
} , function ( data ) {
45
44
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' ] ) ;
49
47
latLngBounds = L . latLngBounds ( latLng , latLng ) ;
50
48
results [ 0 ] = {
51
- name : loc . join ( '.' ) ,
49
+ name : data . words ,
52
50
bbox : latLngBounds ,
53
51
center : latLng
54
52
} ;
0 commit comments