1494d32c9f5059b3b0a99d26a83cb3454aa89e0a
2 * L.Geocoder is used to make geocoding or reverse geocoding requests.
5 L
.Geocoder
= L
.Class
.extend({
7 includes
: L
.Mixin
.Events
,
10 forwardUrl
: L
.geocoderConfig
.forwardUrl
,
11 reverseUrl
: L
.geocoderConfig
.reverseUrl
,
17 initialize: function (callback
, options
) {
18 L
.Util
.setOptions(this, options
);
19 this._user_callback
= callback
;
22 geocode: function (data
) {
23 if (L
.LatLng
&& (data
instanceof L
.LatLng
)) {
24 this._reverse_geocode(data
);
25 } else if (typeof(data
) == 'string') {
26 this.options
.search
= data
;
31 _geocode: function (text
) {
33 this.options
.forwardUrl
,
37 limit
: this.options
.limit
,
38 addressdetails
: this.options
.addressdetails
,
39 "accept-language":this.options
.acceptLanguage
44 _reverse_geocode: function (latlng
) {
46 this.options
.reverseUrl
,
55 _request: function (url
, data
) {
61 jsonp
: 'json_callback',
62 success
: this._callback
,
67 _callback: function (response
,textStatus
,jqXHR
) {
68 var return_location
= {};
69 if(this.options
.search
)
70 return_location
.search
= this.options
.search
;
71 if (((response
instanceof Array
) && (!response
.length
)) || ((response
instanceof Object
) && (response
.error
))) {
72 return_location
.error
= 'not found';
74 return_location
.street
= return_location
.postcode
= return_location
.postcode
=
75 return_location
.locality
= return_location
.region
= return_location
.country
= '';
77 if (response
.length
> 0)
83 var street_components
= [];
85 if (place
.address
.country
) {
86 return_location
.country
= place
.address
.country
;
88 if (place
.address
.country_code
) {
89 return_location
.country_code
= place
.address
.country_code
;
91 if (place
.address
.state
) {
92 return_location
.region
= place
.address
.state
;
94 /* un jour peut-ĂȘtre...
95 if (place.address.county) {
96 return_location.departement = place.address.county;
99 if (place
.address
.city
) {
100 return_location
.locality
= place
.address
.city
;
101 } else if (place
.address
.town
) {
102 return_location
.locality
= place
.address
.town
;
103 } else if (place
.address
.village
) {
104 return_location
.locality
= place
.address
.village
;
105 } else if (place
.address
.county
) {
106 street_components
.push(place
.address
.county
);
108 if (place
.address
.postcode
) {
109 return_location
.postcode
= place
.address
.postcode
;
111 if (place
.address
.road
) {
112 street_components
.push(place
.address
.road
);
113 } else if (place
.address
.pedestrian
) {
114 street_components
.push(place
.address
.pedestrian
);
116 if (place
.address
.house_number
) {
117 street_components
.unshift(place
.address
.house_number
);
119 if (return_location
.street
=== '' && street_components
.length
> 0) {
120 return_location
.street
= street_components
.join(' ');
122 return_location
.point
= new L
.LatLng(place
.lat
, place
.lon
);
124 this._user_callback(return_location
);