/**
 * @class CM_FormField_Location
 * @extends CM_FormField_SuggestOne
 */
var CM_FormField_Location = CM_FormField_SuggestOne.extend({
  _class: 'CM_FormField_Location',

  events: {
    'click .detectLocation': 'detectLocation'
  },

  ready: function() {
    CM_FormField_SuggestOne.prototype.ready.call(this);

    this.on('change', function() {
      this.updateDistanceField();
    }, this);
    var self = this;
    this.getDistanceField().on('ready', function() {
      self.updateDistanceField();
    });
  },

  /**
   * @returns {CM_FormField_Integer|Null}
   */
  getDistanceField: function() {
    if (!this.getOption("distanceName")) {
      return null;
    }
    return this.getForm().getField(this.getOption("distanceName"));
  },

  updateDistanceField: function() {
    if (this.getDistanceField()) {
      var distanceEnabled = false;
      var value = this.getValue();
      if (value) {
        distanceEnabled = value.level >= this.getOption("distanceLevelMin");
      }
      this.getDistanceField().setDisabled(!distanceEnabled);
    }
  },

  /**
   * @return {Object}
   */
  getValue: function() {
    return CM_FormField_SuggestOne.prototype.getValue.call(this);
  },

  /**
   * @param {Object} value
   */
  setValue: function(value) {
    return CM_FormField_SuggestOne.prototype.setValue.call(this, value);
  },

  /**
   * @returns {Promise}
   */
  detectLocation: function() {
    if (!'geolocation' in navigator) {
      throw new CM_Exception('Geolocation support unavailable');
    }
    this.$('.detect-location').addClass('waiting');

    var self = this;

    return new Promise(function(resolve, reject) {
      navigator.geolocation.getCurrentPosition(resolve, reject);
    })
      .then(function(position) {
        return self._lookupCoordinates(position.coords.latitude, position.coords.longitude);
      })
      .then(function(data) {
        if (data) {
          self.setValue(data);
        }
      })
      .catch(function(error) {
        self.error(cm.language.get('Unable to detect location'));
      })
      .finally(function() {
        self.$('.detect-location').removeClass('waiting');
      });
  },

  /**
   * @param {Number} lat
   * @param {Number} lon
   * @return {Promise}
   */
  _lookupCoordinates: function(lat, lon) {
    return this.ajax('getSuggestionByCoordinates', {lat: lat, lon: lon, levelMin: this.getOption('levelMin'), levelMax: this.getOption('levelMax')});
  }
});

@@ -305,24 +305,61 @@
 all(this);%0A%0A
+    if (this.getDistanceField()) %7B%0A  
     this.on(
@@ -377,24 +377,26 @@
 unction() %7B%0A
+  
       this.u
@@ -421,16 +421,18 @@
 ();%0A    
+  
 %7D, this)
@@ -433,24 +433,26 @@
  this);%0A    
+ 
+ 
 var self = t
@@ -456,16 +456,19 @@
 = this;%0A
+%0A  
     this
@@ -514,24 +514,26 @@
 n() %7B%0A      
+  
 self.updateD
@@ -548,28 +548,36 @@
 ield();%0A    
+ 
+ 
 %7D);%0A
+    %7D%0A
   %7D,%0A%0A  /**%0A

Fix Location's Distance detection.