Permalink
Browse files

Adjusted the search page

  • Loading branch information...
1 parent 9a8a15c commit 3df835ed70964af4fe9c3f3fdc97d3b383e8a17d @zachwill zachwill committed Aug 23, 2011
Showing with 37 additions and 12 deletions.
  1. +35 −11 dashboard/static/js/autocomplete.js
  2. +2 −1 dashboard/templates/search.html
@@ -1,18 +1,42 @@
-$(function() {
+(function(window, $) {
+
+ window._results = {};
+
var search = $('input[type="text"]'),
geocoder = new google.maps.Geocoder();
search.autocomplete({
- source: function(request, response){
+ select: function(event, ui) {
+ var url = '/search/?',
+ value = ui.item.value,
+ parameters = window._results[value];
+ parameters['q'] = value;
+ console.log(parameters);
+ window.location = url + $.param(parameters);
+ },
+ source: function(request, response) {
// Grab the source objects from Google Maps.
- geocoder.geocode({'address': request.term}, function(results, status){
- response($.map(results, function(item){
- return {
- label: item.formatted_address,
- value: item.formatted_address
- }
- }));
- });
+ var southwest = new google.maps.LatLng(37.68, -122.57),
+ northeast = new google.maps.LatLng(37.84, -122.35),
+ bounds = new google.maps.LatLngBounds(southwest, northeast);
+
+ geocoder.geocode({
+ 'address': request.term,
+ 'bounds': bounds
+ }, function(results, status){
+ response($.map(results, function(item){
+ var location = item.geometry.location,
+ coordinates = {
+ 'lat': location.lat(),
+ 'lng': location.lng()
+ };
+ window._results[item.formatted_address] = coordinates;
+ return {
+ label: item.formatted_address,
+ value: item.formatted_address
+ }
+ }));
+ });
}
});
-});
+})(window, jQuery);
@@ -13,7 +13,8 @@
<form action="." method="GET">
<label for="q">Type in an address or intersection: </label>
- <input type="text" name="q" value="{{ query|escape }}">
+ <input type="text" name="q" value="{{ query|escape }}"
+ autocomplete="off" autocorrect="off">
<input type="submit" value="Search">
</form>
</div>

0 comments on commit 3df835e

Please sign in to comment.