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
) {
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
;
96 if (place.address.county) {
97 return_location.departement = place.address.county;
100 if (place
.address
.city
) {
101 return_location
.locality
= place
.address
.city
;
102 } else if (place
.address
.town
) {
103 return_location
.locality
= place
.address
.town
;
104 } else if (place
.address
.village
) {
105 return_location
.locality
= place
.address
.village
;
106 } else if (place
.address
.county
) {
107 street_components
.push(place
.address
.county
);
109 if (place
.address
.postcode
) {
110 return_location
.postcode
= place
.address
.postcode
;
112 if (place
.address
.road
) {
113 street_components
.push(place
.address
.road
);
114 }else if(place
.address
.pedestrian
){
115 street_components
.push(place
.address
.pedestrian
);
117 if (place
.address
.house_number
) {
118 street_components
.unshift(place
.address
.house_number
);
121 if (return_location
.street
=== '' && street_components
.length
> 0) {
122 return_location
.street
= street_components
.join(' ');
125 return_location
.point
= new L
.LatLng(place
.lat
, place
.lon
);
127 this._user_callback(return_location
);