{"size": 2092, "ext": "js", "max_stars_repo_path": "public/client/geocoder.js", "max_stars_repo_name": "isabella232/transpochoices", "max_stars_repo_stars_event_min_datetime": "2015-11-05T02:17:39.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-04T18:08:29.000Z", "max_issues_repo_path": "public/client/geocoder.js", "max_issues_repo_name": "codeforamerica/transpochoices", "max_issues_repo_issues_event_min_datetime": "2021-04-17T10:16:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-17T10:16:15.000Z", "max_forks_repo_path": "public/client/geocoder.js", "max_forks_repo_name": "isabella232/transpochoices", "max_forks_repo_forks_event_min_datetime": "2021-04-17T10:14:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-17T10:14:54.000Z"}
{"max_stars_count": 3, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 36.701754386, "max_line_length": 150, "alphanum_fraction": 0.6352772467}
var TranspoChoices = TranspoChoices || {};

(function(tc) {
  tc.geocoder = function(){
    var self = {},
      geocoder = new google.maps.Geocoder(),
      //Default to the continental US
      bounds = new google.maps.LatLngBounds(new google.maps.LatLng(-124.4, 32.5), new google.maps.LatLng(-66.7, 47.4)),
      region = 'US';

    self.currentLocationStr = 'Current Location';

    self.setCurrentLocation = function() {
      if (navigator.geolocation && navigator.geolocation.getCurrentPosition) {
        navigator.geolocation.getCurrentPosition(function(position) {
          self.currentLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
          bounds = new google.maps.Circle({center:self.currentLatLng, radius:8000}).getBounds();

          $(tc).trigger('current-location', [self.currentLocationStr, self.currentLatLng]);
        }, function() {
          tc.util.log('error getting location');
        },
        {enableHighAccuracy:true});
      }
    };

    self.geocode = tc.util.limit(function(addr, callback) {
      geocoder.geocode({'address':addr, 'bounds':bounds, 'region': region }, function(results, status) {
        //If this could be "Current Location", then put on the top of the list
        if (self.currentLatLng && typeof addr === 'string' && addr && self.currentLocationStr.toLowerCase().indexOf(addr.trim().toLowerCase()) > -1) {
          results.unshift({
            currentLocation: true,
            formatted_address: self.currentLocationStr,
            geometry: {
              location: self.currentLatLng
            }
          });
        }

        callback(results);
      });
    }, 750, true);

    //Init and monitor the current location if available
    //Using getCurrentPosition with setInterval b/c Safari on iPhone wasn't
    //respecting the maximumAge
    if (navigator.geolocation && navigator.geolocation.getCurrentPosition) {
      self.setCurrentLocation();

      setInterval(function(){
        self.setCurrentLocation();
      }, 30000);
    }

    return self;
  };
})(TranspoChoices);