0
我有以下GeoLocation腳本來查找用戶的位置。點擊時如何合併按鈕以便在移動位置時刷新用戶的位置?換句話說,我正在尋找一個html按鈕,點擊時刷新用戶的位置。刷新用戶位置的地理位置腳本
// Find user's location start
jQuery(window).ready(function() {
geo_latitude = jQuery.cookie('geo_latitude');
geo_longitude = jQuery.cookie('geo_longitude');
jQuery.cookie('the_cookie', 'the_value', { expires: 7 });
if(null!=geo_latitude && null!=geo_longitude){
var position = {
coords : { latitude : geo_latitude, longitude : geo_longitude }
};
handle_geolocation_query(position);
}else{
initiate_geolocation();
}
})
function initiate_geolocation() {
console.log('initiate_geolocation');
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(handle_geolocation_query, handle_errors);
} else {
yqlgeo.get('visitor', normalize_yql_response);
}
}
function handle_errors(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
alert("User did not share geolocation data");
break;
case error.POSITION_UNAVAILABLE:
alert("Could not detect current position");
break;
case error.TIMEOUT:
alert("Retrieving position timed out");
break;
default:
alert("Unknown Error");
break;
}
}
function normalize_yql_response(response) {
if(response.error) {
var error = {
code : 0
};
handle_error(error);
return;
}
var position = {
coords : {
latitude : response.place.centroid.latitude,
longitude : response.place.centroid.longitude
},
address : {
city : response.place.locality2.content,
region : response.place.admin1.content,
country : response.place.country.content
}
};
handle_geolocation_query(position);
}
function handle_geolocation_query(position) {
jQuery.cookie('geo_latitude', position.coords.latitude);
jQuery.cookie('geo_longitude', position.coords.longitude);
var image_url = "http://maps.google.com/maps/api/staticmap?sensor=false¢er=" + position.coords.latitude + "," + position.coords.longitude + "&zoom=12&size=400x116&style=feature:water|element:geometry|hue:0x336699|saturation:30|lightness:25&style=feature:road.highway|element:labels|visibility:off&style=feature:transit|element:all|visibility:off&markers=icon:http%3A%2F%2Fwww.jabbermap.com%2Fwp-content%2Fuploads%2Fimages%2Fmarker.png|" + position.coords.latitude + ',' + position.coords.longitude;
jQuery("#map").remove();
jQuery('#welcome_map').append(jQuery(document.createElement("img")).attr("src", image_url).attr('id', 'map'));
}
// Find user's location end
// Slider start: http://www.webchief.co.uk/blog/simple-jquery-slideshow/index.php
jQuery(document).ready(function() {
var currentPosition = 0;
var slideWidth = 630;
var slides = jQuery('.slide');
var numberOfSlides = slides.length;
var slideShowInterval;
var speed = 8000;
slideShowInterval = setInterval(changePosition, speed);
slides.wrapAll('<div id="slidesHolder"></div>')
slides.css({ 'float' : 'left' });
jQuery('#slidesHolder').css('width', slideWidth * numberOfSlides);
function changePosition() {
if(currentPosition == numberOfSlides - 1) {
currentPosition = 0;
} else {
currentPosition++;
}
moveSlide();
}
function moveSlide() {
jQuery('#slidesHolder').animate({'marginLeft' : slideWidth*(-currentPosition)});
}
});
// Slider end