I use this to geolocate the user and I need the values of currentLat
and currentLon
stored in a var:
<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>
I need those values in here:
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=my_key&radius_units=km&radius=5&lat= XXX &lon= XXX &jsoncallback=?
How do I get the values through jQuery and put them in the URL immediately? What's the quickest way?
Thanks @Manuel but I have used it like this first as I don't need the error function, just to keep it simple so I can understand it but doesn't work?!
$(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
});
} }
})
in the var url
you'll get find the url with the lat an lon filled in
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var url = 'http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=my_key&radius_units=km&radius=5&lat='+lat+'&lon='+lon+'&jsoncallback=?';
// console.log(url);
}, function(error) {
console.log("Something went wrong: ", error);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.