0
我用這個來地理定位的用戶,我需要存儲在VAR的currentLat
和currentLon
值:HTML5地理位置
<script>
window.onload = function() {
var startPos;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
startPos = position;
document.getElementById("currentLat").innerHTML = startPos.coords.latitude;
document.getElementById("currentLon").innerHTML = startPos.coords.longitude;
});
}
};
</script>
我需要這些值在這裏:
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=my_key&radius_units=km&radius=5&lat= XXX &lon= XXX &jsoncallback=?
我如何通過jQuery獲取值並將它們立即放入URL中?什麼是最快的方法?
感謝@Manuel但我已經用它這樣的第一,因爲我不需要誤差函數,只是爲了保持它的簡單,所以我可以理解,但不工作?
$(document).ready(function() {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var JSONURL = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=my_key&format=json&privacy_filter=1&media=photos&tag=london&minwidth=700&has_geo=1&accuracy=11&content_type=1&extras=geo,owner_name,url_m&page=1&radius_units=km&radius=5&"+lat+"&lon="+lon+"&jsoncallback=?";
jQuery.getJSON(JSONURL, getJSONimages);
function getJSONimages(data) {
var htmlString = "";
$.each(data.photos.photo, function(i,item){
var itemTitle = item.title;
});
$('#slideshow').html(htmlString);
$('#slideshow').slideshow({
timeout: 3000,
type: 'random',
fadetime: 2000
});
} }
})