Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Now accepting options.
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiSG committed Aug 14, 2010
1 parent a009d2d commit 43f0050
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
14 changes: 13 additions & 1 deletion Demo/Meio.Autocomplete.Geo.html
Expand Up @@ -37,7 +37,19 @@ <h1>Meio.Autocomplete.Geo demo</h1>

<script type="text/javascript">
//<![CDATA[
new Meio.Autocomplete.Geo('form_school', ['test', 'test2']);
var latlng1 = new google.maps.LatLng(43.62538544065392, 7.011492675781259);
var latlng2 = new google.maps.LatLng(43.5895879439408, 7.104876464843759);
var bounds = new google.maps.LatLngBounds();
bounds.extend(latlng1);
bounds.extend(latlng2);

var geopleter = new Meio.Autocomplete.Geo('form_school', {
region: 'fr',
bounds: bounds,
location: new google.maps.LatLng(43.62028086118892, 7.043044841527948)
}, {
delay: 0
});
//]]>
</script>
</body>
Expand Down
58 changes: 31 additions & 27 deletions Source/Meio.Autocomplete.Geo.js
Expand Up @@ -6,27 +6,24 @@
Meio.Autocomplete.Data.Geo = new Class({

Extends: Meio.Autocomplete.Data,


geocoder: new google.maps.Geocoder(),

/**Available options, from http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderRequest
* address string Address. Optional.
* bounds LatLngBounds LatLngBounds within which to search. Optional.
* language string Preferred language for results. Optional.
* location LatLng LatLng about which to search. Optional.
* region string Country code top-level domain within which to search. Optional.
*/
options: {
},

geocoder: new google.maps.Geocoder(),

initialize: function init(geocoderReqOpts, cache) {
initialize: function init(geocoderReqOpts) {
this._cache = new Meio.Autocomplete.Cache();
this.setOptions(geocoderReqOpts);
this.geocoderReqOpts = geocoderReqOpts; //we can't use Options because they change the prototype
},

prepare: function(text){
this.cachedKey = text;
if (this._cache.has(this.cachedKey)){
if (this._cache.has(this.cachedKey)) {
this.data = this._cache.get(this.cachedKey);
this.fireEvent('ready');
} else {
Expand All @@ -35,8 +32,15 @@ Meio.Autocomplete.Data.Geo = new Class({
},

search: function(query) {
var ro = this.geocoderReqOpts;
this.geocoder.geocode(
$merge(this.geocoderOpts, {address: query}),
{ //we can't use $merge because it changes the subobjects' prototypes
address: query,
bounds: ro.bounds,
language: ro.language,
location: ro.location,
region: ro.region
},
this.handleResults.bind(this)
);
},
Expand All @@ -52,28 +56,28 @@ Meio.Autocomplete.Data.Geo = new Class({
}
}
});



Meio.Autocomplete.Geo = new Class({
Extends: Meio.Autocomplete,

options: {
filter: {
path: 'formatted_address'
},
/**Available options, from http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderRequest
* address string Address. Optional.
* bounds LatLngBounds LatLngBounds within which to search. Optional.
* language string Preferred language for results. Optional.
* location LatLng LatLng about which to search. Optional.
* region string Country code top-level domain within which to search. Optional.
*/
geocoderRequest: {
}

/**Available options, from http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderRequest
* bounds LatLngBounds LatLngBounds within which to search.
* language string Preferred language for results.
* location LatLng LatLng about which to search.
* region string Country code top-level domain within which to search.
*/
initialize: function(input, geocoderRequestOptions, options, listInstance){
this.geocoderRequestOptions = geocoderRequestOptions; //we can't use Options because they change the prototype
options = $merge(options, {
filter: {
path: 'formatted_address'
}
});
this.parent(input, [], options, listInstance);
},

initData: function() {
this.data = new Meio.Autocomplete.Data.Geo(this.options.geocoderRequest);
this.data = new Meio.Autocomplete.Data.Geo(this.geocoderRequestOptions);
this.data.addEvent('ready', this.dataReady.bind(this));
}
});

0 comments on commit 43f0050

Please sign in to comment.