Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript OpenWeatherMapAPI-附加经度和纬度的问题_Javascript_Ajax_Callback_Openweathermap - Fatal编程技术网

Javascript OpenWeatherMapAPI-附加经度和纬度的问题

Javascript OpenWeatherMapAPI-附加经度和纬度的问题,javascript,ajax,callback,openweathermap,Javascript,Ajax,Callback,Openweathermap,我试图根据用户的经度和纬度来定义搜索城市,我通过.geolocation 当把long和lat添加到我的url时,我得到了这个错误 cod : "400" message : "-104.9435462 is not a float" getLocation(); //查找设备的位置 函数getLocation(回调){ if(导航器.地理位置){ navigator.geolocation.getCurrentPosition(getData); } } //

我试图根据用户的经度和纬度来定义搜索城市,我通过
.geolocation

当把long和lat添加到我的url时,我得到了这个错误

cod    :    "400"    message    :    "-104.9435462 is not a float"
getLocation();
//查找设备的位置
函数getLocation(回调){
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(getData);
}
}
//获取/设置变量
函数getData(位置){
var经度=position.coords.longitude;
变量纬度=位置坐标纬度;
var高度=位置坐标高度;
var航向=position.coords.heading;
var速度=位置坐标速度;
var日期=位置。时间戳;
获取天气(经度、纬度);
console.log(经度);
控制台日志(纬度);
}
//调用OpenWeatherAPI
函数getWeather(x,y){
常数apiKey='';
var url='1〕http://api.openweathermap.org/data/2.5/forecast?lat=“+x+”&lon=“+y+”&APPID=280e605c456f0ba78a519edde1a641d3”;
$.ajax({
url:url,
成功:功能(结果){
}
});
}; //结束getWeather()

迟交答案,但希望这能节省其他人的时间。错误消息具有误导性

发生此错误是因为经度(范围为-180到180)位于纬度(范围为-90到90)。

在代码中,getWeather()调用如下:

getWeather(longitude, latitude);
但是,请注意,纬度和经度(x,y)在函数中是按顺序排列的(纬度,经度):

  function getWeather(x, y) {
  const apiKey = '';
  var url = 'http://api.openweathermap.org/data/2.5/forecast?lat=' + x + '&lon=' + y + '&APPID= removed id';
// additional code
}; 
更改呼叫可以解决以下问题:

getWeather(latitude, longitude);

迟交答案,但希望这能节省其他人的时间。错误消息具有误导性

发生此错误是因为经度(范围为-180到180)位于纬度(范围为-90到90)。

在代码中,getWeather()调用如下:

getWeather(longitude, latitude);
但是,请注意,纬度和经度(x,y)在函数中是按顺序排列的(纬度,经度):

  function getWeather(x, y) {
  const apiKey = '';
  var url = 'http://api.openweathermap.org/data/2.5/forecast?lat=' + x + '&lon=' + y + '&APPID= removed id';
// additional code
}; 
更改呼叫可以解决以下问题:

getWeather(latitude, longitude);

你解决了吗?我解决了,但我选择了api.wunderground.com,因为他们的api中有自动定位功能。你解决了吗?我解决了,但我选择了api.wunderground.com,因为他们的api中有自动定位功能