Create Proximity Searches

Registered by Robbi on 2010-09-02

Create proximity searches

Blueprint information

Needs approval
Douglas Huston
Series goal:
Accepted for couchapp-backbone
Milestone target:
milestone icon 0.3
Started by
Tim Black on 2011-04-20
Completed by
Douglas Huston on 2015-04-21

Related branches




Created form elements, but have not yet gotten the AJAX request to Google to geocode the location to send from those form elements onkeyup. So, start in the Javascript file named search_the_map.js.

1) User Interface: allow entry of:
     A) location textbox: city, state, zip, or full address
     B) radius drop-down
     C) units drop-down (miles/kilometers)
1.1) In JavaScript, handle this input.
     A) Geocode address using Google's proximity API.
     B) Center map on that geocode's lat/lon.
     C) Set map's zoom using radius*units -> convert to appropriate zoom level by map.fitBounds(circle.getBounds())
     D) Send AJAX request to Python controller method (arguments: map's lat/lon boundaries) to get list of congregations whose lat/lon coordinates fall within the lat/lon boundaries of the map. Implemented in
         - Maybe: Go to to find out how to compute the distance between two LAT/LON entries.
         - Controller method: return JSON list of cong lat/lon geocodes, other cong data to display in map bubble & tablesorter widget.
     E) Handle AJAX response:
        - plot returned congregations on the map, creating a bubble for each congregation.
          - Put more congregation data in each bubble:  city, state, zip, phone number, website URL link, "Directions to" link
        - list returned congregations in the tablesorter widget
          - Fix formatting in table's contact info column
1.2) Use geocouch on iriscouch
2) Improve User Interface:
   - Try to be able to guess which unit of distance (Mi or KM) they prefer based on some input from the user. TODO: Figure out the right order of if-clauses to use below, and outline it in comments in the code.
     * Event Handler: On page load
       * If the distance unit localstorage preference is set, set the distance units in the form based on what is in the localstorage preference.
       * Else, on page load, before the person searches, guess what units they want based on one of the following:
         * First try the users' browser's geolocation information. Google for "calculate distance units from geolocation" to see how others have done this. You can geocode the location using = new google.maps.Geocoder();, then filter (using the Underscore.js _.filter() method) for results[0].address_components[x].types.short_name == 'US', then if the user is in one of the countries that use miles, select "miles" in the form and save it to the localstorage preference. Those countries which use miles are:
     -- (LBR / LR / 430) Liberia
     -- (MMR / MM / 104) Myanmar
     -- (GBR / GB / 826) United Kingdom
     -- (USA / US / 840) United States
         * Next, try the browser country or language setting. Use "var userLang = navigator.language || navigator.browserLanguage || navigator.systemLanguage || navigator.userLanguage;"
         * Last try figuring it based on the country in which they are searching
         * Next try their IP address. Here's an easy way to do it:
     * Event handler: On click of the distance units drop-down box, record the currently-selected distance unit in a localstorage preference, and record there that the user selected it manually.
     * Event handler: On search form submission, record the currently-selected distance unit in a localstorage preference, and record there whether they selected it manually or not.
     * Event handler: On search results being returned to the browser from the Google Maps API, Google's geocode responses state in which country the searched-for location is found, so after they search, you can set their distance units for them (in a localstorage preference and in the form) based on the country, unless (in a localstorage preference you can see) they have already selected a distance unit manually.
* Figure out why, after the above work to save the distance units preference, after typing an address in the location search box, there is an error in the JavaScript console, and the map does not center on that location.


Work Items

This blueprint contains Public information 
Everyone can see this information.


No subscribers.