lat
我想使用地理定位来获取我当前的位置并且它可以工作,然后我想解析lon
应该是我的位置的 xml。但是我的代码在这里似乎有些问题:
url: "http://**/festivalapi.php? method=getPhotos&returntype=xml&lat=" + mylat + "&lon="+ mylong ",
但是如果我直接使用 lat 和 lon 就可以了。像这样:
url: http://**/festivalapi.php? method=getPhotos&returntype=xml&lat=54.911859&lon=-1.343404`
所以我认为这里一定是一些语法错误..
这是整个jquery:
$(document).ready(function () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(displayPosition, errorFunction, { enableHighAccuracy: true, maximumAge: 30000, timeout: 27000 });
} else {
alert('It seems like Geolocation, which is required for this page, is not enabled in your browser. Please use a browser which supports it.');
}
function displayPosition(pos) {
var mylat = pos.coords.latitude;
var mylong = pos.coords.longitude;
var thediv = document.getElementById('locationinfo');
thediv.innerHTML = '<p>Your latitide is :' +
mylat + ' and your longitude is ' + mylong + '</p>';
}
// Error callback function
function errorFunction(pos) {
alert('Error!');
}
$.ajax({
type: "GET",
url: "http://**/festivalapi.php? method=getPhotos&returntype=xml&lat=" + mylat + "&lon="+ mylong ",
dataType: "xml",
success: function (xml) {
$(xml).find('photo').each(function () {
var name = $(this).find('name').text();
var url = $(this).find('url').text();
$('<li></li>').append("<img src='" + url + "'/>").appendTo('#photos');
});
},
error: function () {
alert('Sorry, an error occured loading the XML file');
}
});
});