Added errorCallback() to geoCurrentPosition() i.e., if user doesn't

grant permission, removes the Geo processing and (if any) existing geo
location data from notice form.
This commit is contained in:
Sarven Capadisli 2010-01-04 09:52:35 +00:00
parent d1998adb13
commit fe8927a42c

View File

@ -493,44 +493,57 @@ var SN = { // StatusNet
return false; return false;
}); });
navigator.geolocation.getCurrentPosition(function(position) { navigator.geolocation.getCurrentPosition(
$('#'+SN.C.S.NoticeLat).val(position.coords.latitude); function(position) {
$('#'+SN.C.S.NoticeLon).val(position.coords.longitude); $('#'+SN.C.S.NoticeLat).val(position.coords.latitude);
$('#'+SN.C.S.NoticeLon).val(position.coords.longitude);
var data = { var data = {
'lat': position.coords.latitude, 'lat': position.coords.latitude,
'lon': position.coords.longitude, 'lon': position.coords.longitude,
'token': $('#token').val() 'token': $('#token').val()
}; };
$.getJSON(geocodeURL, data, function(location) { $.getJSON(geocodeURL, data, function(location) {
NLN.replaceWith('<a id="notice_data-location_name"/>'); NLN.replaceWith('<a id="notice_data-location_name"/>');
NLN = $('#'+SN.C.S.NoticeLocationName); NLN = $('#'+SN.C.S.NoticeLocationName);
if (typeof(location.location_ns) != 'undefined') { if (typeof(location.location_ns) != 'undefined') {
$('#'+SN.C.S.NoticeLocationNs).val(location.location_ns); $('#'+SN.C.S.NoticeLocationNs).val(location.location_ns);
} }
if (typeof(location.location_id) != 'undefined') { if (typeof(location.location_id) != 'undefined') {
$('#'+SN.C.S.NoticeLocationId).val(location.location_id); $('#'+SN.C.S.NoticeLocationId).val(location.location_id);
} }
if (typeof(location.name) == 'undefined') { if (typeof(location.name) == 'undefined') {
NLN_text = position.coords.latitude + ';' + position.coords.longitude; NLN_text = position.coords.latitude + ';' + position.coords.longitude;
} }
else { else {
NLN_text = location.name; NLN_text = location.name;
} }
NLN.attr('href', location.url); NLN.attr('href', location.url);
NLN.text(NLN_text); NLN.text(NLN_text);
NLN.click(function() { NLN.click(function() {
window.open(location.url); window.open(location.url);
return false; return false;
});
}); });
}); },
});
function(error) {
if (error.PERMISSION_DENIED == 1) {
$('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked');
NDGS.hide();
$('#'+SN.C.S.NoticeLat).val('');
$('#'+SN.C.S.NoticeLon).val('');
$('#'+SN.C.S.NoticeLocationNs).val('');
$('#'+SN.C.S.NoticeLocationId).val('');
}
}
);
} }
else { else {
$('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked'); $('label[for='+SN.C.S.NoticeDataGeo+']').removeClass('checked');