Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
hitching committed Sep 20, 2009
1 parent af3fba2 commit 2fa96f1
Show file tree
Hide file tree
Showing 4 changed files with 1,013 additions and 0 deletions.
66 changes: 66 additions & 0 deletions demo/index.html
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<title>jQuery geo_Autocomplete Plugin</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>

<!--
jquery.autocomplete.js requires a minor modification for geo_autocomplete to work
the following script includes the required mod
-->
<script type="text/javascript" src="../lib/jquery.autocomplete_geomod.js"></script>

<script type="text/javascript" src="../geo_autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="../lib/jquery.autocomplete.css" />

<script type="text/javascript">
$().ready(function() {

var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

// use all the autocomplete options as documented at http://docs.jquery.com/Plugins/Autocomplete
/* additional geo_autocomplete options:
mapkey : 'ABQ...' (required for Static Maps thumbnails, obtain a key for your site from http://code.google.com/apis/maps/signup.html)
mapwidth : 100
mapheight : 100
maptype : 'terrain' (see http://code.google.com/apis/maps/documentation/staticmaps/#MapTypes)
mapsensor : true or false
*/
$('#location').geo_autocomplete(new google.maps.Geocoder, {
mapkey: 'ABQIAAAAbnvDoAoYOSW2iqoXiGTpYBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQNumU68AwGqjbSNF9YO8NokKst8w',
selectFirst: false,
minChars: 3,
cacheLength: 50,
width: 300,
scroll: true,
scrollHeight: 330
}).result(function(_event, _data) {
if (_data) map.fitBounds(_data.geometry.viewport);
});

});
</script>
<style>
.ac_results li img {
float: left;
margin-right: 5px;
}
</style>
</head>
<body>
<h1><a href="http://code.google.com/p/geo-autocomplete">jQuery geo_Autocomplete Plugin</a> Demo</h1>

<div>Location: <input type="text" id="location" /> (autocomplete)</div>
<br/>
<div id="map_canvas" style="width:500px;height:350px;"/>

</body>
</html>
78 changes: 78 additions & 0 deletions geo_autocomplete.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* jQuery geo_autocomplete plugin 1.0
*
* Copyright (c) 2009 Bob Hitching
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Requires jQuery Autocomplete plugin by Jörn Zaefferer - see http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
* modified by adding the following code before the line in function request starting '} else if( (typeof options.url == "string") ...'
} else if (options.geocoder) {
var _query = lastWord(term);
options.geocoder.geocode({'address': _query}, function(_results, _status) {
var parsed = options.parse(_results, _status, _query);
cache.add(term, parsed);
success(term, parsed);
});
*
* See ... tbc ... for more details on implementation
*
*/
;(function($) {

$.fn.extend({
geo_autocomplete: function(_geocoder, _options) {
options = $.extend({}, $.Autocompleter.defaults, {
geocoder: _geocoder,
mapwidth: 100,
mapheight: 100,
maptype: 'terrain',
mapkey: 'ABQIAAAAbnvDoAoYOSW2iqoXiGTpYBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQNumU68AwGqjbSNF9YO8NokKst8w', // localhost
mapsensor: false,
parse: function(_results, _status, _query) {
var _parsed = [];
if (_results && _status && _status == 'OK') {
$.each(_results, function(_key, _result) {
if (_result.geometry && _result.geometry.viewport) {
// place is first matching segment, or first segment
var _place_parts = _result.formatted_address.split(',');
var _place = _place_parts[0];
$.each(_place_parts, function(_key, _part) {
if (_part.toLowerCase().indexOf(_query.toLowerCase()) != -1) {
_place = $.trim(_part);
return false; // break
}
});
_parsed.push({
data: _result,
value: _place,
result: _place
});
}
});
}
return _parsed;
},
formatItem: function(_data, _i, _n, _value) {
var _src = 'http://maps.google.com/maps/api/staticmap?visible=' + _data.geometry.viewport.getSouthWest().toUrlValue() + '|' + _data.geometry.viewport.getNorthEast().toUrlValue() + '&size=' + options.mapwidth + 'x' + options.mapheight + '&maptype=' + options.maptype + '&key=' + options.mapkey + '&sensor=' + (options.mapsensor ? 'true' : 'false');
var _place = _data.formatted_address.replace(/,/gi, ',<br/>');
return '<img src="' + _src + '" width="' + options.mapwidth + '" height="' + options.mapheight + '" /> ' + _place + '<br clear="both"/>';
}
}, _options);

// if highlight is set to false, replace it with a do-nothing function
options.highlight = options.highlight || function(value) { return value; };

// if the formatMatch option is not specified, then use formatItem for backwards compatibility
options.formatMatch = options.formatMatch || options.formatItem;

return this.each(function() {
new $.Autocompleter(this, options);
});
}
});

})(jQuery);
48 changes: 48 additions & 0 deletions lib/jquery.autocomplete.css
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,48 @@
.ac_results {
padding: 0px;
border: 1px solid black;
background-color: white;
overflow: hidden;
z-index: 99999;
}

.ac_results ul {
width: 100%;
list-style-position: outside;
list-style: none;
padding: 0;
margin: 0;
}

.ac_results li {
margin: 0px;
padding: 2px 5px;
cursor: default;
display: block;
/*
if width will be 100% horizontal scrollbar will apear
when scroll mode will be used
*/
/*width: 100%;*/
font: menu;
font-size: 12px;
/*
it is very important, if line-height not setted or setted
in relative units scroll will be broken in firefox
*/
line-height: 16px;
overflow: hidden;
}

.ac_loading {
background: white url('indicator.gif') right center no-repeat;
}

.ac_odd {
background-color: #eee;
}

.ac_over {
background-color: #0A246A;
color: white;
}
Loading

0 comments on commit 2fa96f1

Please sign in to comment.