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
: 'http://open.mapquestapi.com/nominatim/v1/search',
11 reverseUrl
: 'http://open.mapquestapi.com/nominatim/v1/reverse',
16 initialize: function (callback
, options
) {
17 L
.Util
.setOptions(this, options
);
18 this._user_callback
= callback
;
21 geocode: function (data
) {
22 if (L
.LatLng
&& (data
instanceof L
.LatLng
)) {
23 this._reverse_geocode(data
);
24 } else if (typeof(data
) == 'string') {
29 _geocode: function (text
) {
31 this.options
.forwardUrl
,
35 limit
: this.options
.limit
,
36 addressdetails
: this.options
.addressdetails
41 _reverse_geocode: function (latlng
) {
43 this.options
.reverseUrl
,
52 _request: function (url
, data
) {
58 jsonp
: 'json_callback',
59 success
: this._callback
,
64 _callback: function (response
) {
65 var return_location
= {};
66 if (response
instanceof Array
&& !response
.length
) {
69 return_location
.street
= '';
70 return_location
.postcode
= '';
71 return_location
.locality
= '';
72 return_location
.region
= '';
73 return_location
.country
= '';
75 if (response
.length
> 0) {
81 var street_components
= [];
83 if (place
.address
.country
) {
84 return_location
.country
= place
.address
.country
;
86 if (place
.address
.state
) {
87 return_location
.region
= place
.address
.state
;
89 if (place
.address
.city
) {
90 return_location
.locality
= place
.address
.city
;
91 }else if(place
.address
.county
){
92 street_components
.push(place
.address
.pedestrian
);
94 if (place
.address
.postcode
) {
95 return_location
.postcode
= place
.address
.postcode
;
97 if (place
.address
.road
) {
98 street_components
.push(place
.address
.road
);
99 }else if(place
.address
.pedestrian
){
100 street_components
.push(place
.address
.pedestrian
);
102 if (place
.address
.house_number
) {
103 street_components
.unshift(place
.address
.house_number
);
106 if (return_location
.street
=== '' && street_components
.length
> 0) {
107 return_location
.street
= street_components
.join(' ');
110 return_location
.point
= new L
.LatLng(place
.lat
, place
.lon
);
112 this._user_callback(return_location
);