== 'nearest' || jQuery('select[name="sort_by"]', $form).val() == 'farthest')) && (jQuery(".snear", $form).val() == '' || jQuery(".snear", $form).val() == 'Near')) jQuery(".snear", $form).val(default_location);
geocodeAddress($form);
}
function doGeolocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(positionSuccess, positionError);
} else {
positionError(-1);
}
}
function positionError(err) {
var msg;
switch (err.code) {
case err.UNKNOWN_ERROR:
msg = "Unable to find your location";
break;
case err.PERMISSION_DENINED:
msg = "Permission denied in finding your location";
break;
case err.POSITION_UNAVAILABLE:
msg = "Your location is currently unknown";
break;
case err.BREAK:
msg = "Attempt to find location took too long";
break;
default:
msg = "Location detection not supported in browser";
}
jQuery('#info').html(msg);
}
function positionSuccess(position) {
var coords = position.coords || position.coordinate || position;
jQuery('.sgeo_lat').val(coords.latitude);
jQuery('.sgeo_lon').val(coords.longitude);
jQuery('.geodir-listing-search').submit();
}
/**
* On unload page do some cleaning so back button cache does not store these values.
*/
window.onunload = function(){
if(jQuery('.sgeo_lat').length ){
jQuery('.sgeo_lat').val('');
jQuery('.sgeo_lon').val('');
}
};