我正在尝试根据我通过.geolocation
访问的用户的经度和纬度来定义搜索城市>
将long和lat添加到我的网址中时,出现此错误
cod : "400" message : "-104.9435462 is not a float"
getLocation(); //Find Location of Device function getLocation(callback) { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(getData); } } //Get/set Variables function getData(position) { var longitude = position.coords.longitude; var latitude = position.coords.latitude; var altitude = position.coords.altitude; var heading = position.coords.heading; var speed = position.coords.speed; var date = position.timestamp; getWeather(longitude, latitude); console.log(longitude); console.log(latitude); } //Call OpenWeatherAPI function getWeather(x, y) { const apiKey = ''; var url = 'http://api.openweathermap.org/data/2.5/forecast?lat=' + x + '&lon=' + y + '&APPID=280e605c456f0ba78a519edde1a641d3'; $.ajax({ url: url, success: function(result) { } }); }; //END getWeather()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
[我正在尝试根据我通过.geolocation访问的用户的经度和纬度来定义搜索城市,当将long和lat添加到我的网址时,出现此错误编码:“ 400” ...
最新答案,但希望这可以节省其他人的时间。错误消息具有误导性。
之所以发生此错误,是因为将范围为-180至180的经度放置在范围为-90至90的纬度中。