目前正在为iOS的天气web应用程序工作。我试图获取用户的坐标,并将纬度和经度放在我的Ajax请求中(在api Wunderground上)。获取ajax请求的位置坐标
这里是我的代码(编辑):
$(document).ready(function() {
navigator.geolocation.getCurrentPosition(getLocation, unknownLocation);
function getLocation(pos)
{
var lat = pos.coords.latitude;
var lon = pos.coords.longitude;
$.ajax({
url : "http://api.wunderground.com/api/ApiId/geolookup/conditions/q/"+ lat +","+ lon +".json",
dataType : "jsonp",
success : function(parsed_json) {
var location = parsed_json['location']['city'];
var temp_f = parsed_json['current_observation']['temp_f'];
alert("Current temperature in " + location + " is: " + temp_f);
}
});
}
function unknownLocation()
{
alert('Could not find location');
}
});
正如你可以看到我“简单的”要创建2瓦尔纬度和经度,在我的要求添加。我尝试了很多变体,但我无法获得此代码的工作。
任何想法我做错了什么?
非常感谢!
2013-04-18
MonBlaze
+0
您是否注册了API密钥?看起来你需要一个。 –
+0
我有一个,我只是隐藏在我的代码,因为你不需要它:) –