我正在使用openweathermap.org获取城市的天气.
jsonp调用正在运行,一切正常,但生成的对象包含未知单位的温度:
{
//...
"main": {
"temp": 290.38, // What unit of measurement is this?
"pressure": 1005,
"humidity": 72,
"temp_min": 289.25,
"temp_max": 291.85
},
//...
}
Run Code Online (Sandbox Code Playgroud)
这是一个console.log完整对象的演示.
我不认为由此产生的温度是华氏温度,因为将290.38华氏温度转换为摄氏温度143.544.
有谁知道openweathermap返回的温度单位是多少?
javascript json units-of-measurement weather-api openweathermap
我正在使用openweathermap显示天气预报.一切正常,但图标有问题.json响应代码是:
Array
(
[city] => Array
(
[id] => 1271476
[name] => Guwahati
[coord] => Array
(
[lon] => 91.751
[lat] => 26.1862
)
[country] => IN
[population] => 899094
)
[cod] => 200
[message] => 0.0630711
[cnt] => 1
[list] => Array
(
[0] => Array
(
[dt] => 1495688400
[temp] => Array
(
[day] => 33
[min] => 24.89
[max] => 33.82
[night] => 24.89
[eve] => 30.6
[morn] => 33
)
[pressure] => 1013.02
[humidity] => 90 …Run Code Online (Sandbox Code Playgroud) 我是一位探索Android世界的新开发者.我目前正在通过Udacity教程创建Sunshine应用程序.在片段活动类中,为了从openweathermap获取数据,我必须将从我的帐户获得的API密钥添加到生成的URL的末尾.在Fragment活动中调用BuildConfig.java (单击以查看对作为String apiKey的一部分在第6行的BuildConfig.java的调用).
build.gradle文件如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.android.sunshine.app"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', 'c882c94be45fff9d16a1cf845fc16ec5'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
}
Run Code Online (Sandbox Code Playgroud)
在buildTypes.each it.buildConfigField中使用'String','OPEN_WEATHER_MAP_API_KEY','c882c94be45fff9d16a1cf845fc16ec5'调用
public static final String OPEN_WEATHER_MAP_API_KEY = c882c94be45fff9d16a1cf845fc16ec5;
Run Code Online (Sandbox Code Playgroud)
在BuildConfig.java中生成,但我不断收到此错误: 无法解析符号(单击以查看错误消息和BuildConfig.java文件)我不明白为什么字符串OPEN_WEATHER_MAP_API_KEY自动创建为一组字母和数字而没有引用它们,但如果我编辑代码阅读:
public static final String OPEN_WEATHER_MAP_API_KEY = "c882c94be45fff9d16a1cf845fc16ec5";
Run Code Online (Sandbox Code Playgroud)
要么
public static final …Run Code Online (Sandbox Code Playgroud) 如何在Google Maps API 3上叠加XYZ图块集(如下所示)?我想覆盖天气数据(云层等等).随意使用我的OpenWeatherMaps URL来测试它:
http://maps.owm.io:8091/56ce0fcd4376d3010038aaa8/{z}/{x}/{y}?hash=5
Run Code Online (Sandbox Code Playgroud)
我花了好几天试图找出这个看似简单的功能.如果有人可以提供一个有效的例子我会欠你的债.请随意使用此天气数据叠加层的OL3和OSM查看我的GitHub Gist实现.我也很想知道这是不是很容易实现/需要黑客攻击.
谢谢!
更新:感谢@ wf9a5m75的回答,我能够将这个jsFiddle与我的问题的解决方案放在一起:https://jsfiddle.net/601oqwq2/4/
我在使用OpenWeatherMap API时遇到此异常错误.我只是想让结果成为一个JSONObject,但是null仍然会出现.
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// What's coming in as result...
// Printed to the console...
// null{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":800,"main":"Clear",
// "description":"clear sky","icon":"01d"}],...}
try {
JSONObject jsonObject = new JSONObject(result);
String weatherInfo = jsonObject.getString("weather");
Log.i("Weather Info", weatherInfo);
} catch (JSONException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
JSON数据很好,但我想要的是它成为一个JSONObject但是null部分正在捕获.任何想法为什么会发生这种情况?
同样来自网站的JSON Response是:
{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],.....}
Run Code Online (Sandbox Code Playgroud)
为什么一开始没有null?谢谢您的帮助.
我正在尝试使用OpenWeatherMap API为javascript创建一个天气应用程序.我的网络应用程序的代码是:
<!DOCTYPE html>
<html>
<head>
<title>Weather</title>
<script src = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js"></script>
<script>
function gettingJSON(){
document.write("jquery loaded");
$.getJSON("api.openweathermap.org/data/2.5/weather?q=London&APPID=ee6596241130f193adf1ba90e625cc10",function(json){
document.write(json);
}
</script>
</head>
<body>
<button id = "getIt" onclick = "gettingJSON()">Get JSON</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我在这里弄错了什么?
在我的应用程序中,我想使用OpenWeatherMap api 来显示城市天气信息。
为此,我想将描述 语言更改为farsi。
我在OpenWeatherMap帮助下得到了这个,我在下面写了URL:
http://api.openweathermap.org/data/2.5/forecast/daily?q=tehran,ir&cnt=16&units=metric&lang=Farsi-fa&appid=1487dd8a93bfd85d278d9ayty875ghyy
Run Code Online (Sandbox Code Playgroud)
但是给我看这个信息:
{
"city": {
"id": 112931,
"name": "Tehran",
"coord": {
"lon": 51.4014,
"lat": 35.7006
},
"country": "IR",
"population": 7153309
},
"cod": "200",
"message": 1.31599,
"cnt": 16,
"list": [
{
"dt": 1522310400,
"temp": {
"day": 29.68,
"min": 9.13,
"max": 29.68,
"night": 9.13,
"eve": 19.21,
"morn": 29.68
},
"pressure": 749.02,
"humidity": 67,
"weather": [
{
"id": 801,
"main": "Clouds",
"description": "few clouds",
"icon": "02d" …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 API 获取当前天气,出于某种原因,当我尝试创建 Retrofit 对象时,它返回一个错误:
Process: com.api.weather_api_training, PID: 8417
java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
at okhttp3.internal.Util.<clinit>(Util.java:87)
at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Util.java:321)
at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1313)
at okhttp3.HttpUrl.get(HttpUrl.java:917)
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:506)
at com.api.weather_api_training.MainActivity.onCreate(MainActivity.java:31)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Run Code Online (Sandbox Code Playgroud)
这是我的 build.gradle 文件:
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现一个iPhone应用程序,我正在集成OpenWeatherMap来检索当前的天气.但是,我注意到返回的数据不正确(大约39华氏度).
下面是我用于使用Lan/Lon坐标检索Denver,Usa的当前天气的JSON URL,其中xxxxxxxxxxxxx是我的APPID密钥.
http://api.openweathermap.org/data/2.5/weather?APPID=xxxxxxxxxxxxx&lat=39.738539&lon=-104.981114
Run Code Online (Sandbox Code Playgroud)
返回的温度为291.05988.从文档读取,这个温度单位是开尔文.所以为了转换为Fahrenhiet,我采取291.05988 - 254.928 = 36.13188华氏度.然而,真正的当前天气是75华氏度.这是约39度.
请告诉我我做错了什么.
谢谢Loc
我正在做一个简单的前端项目,我(或用户)在其中对 openweathermap api 进行 API 调用,获取天气信息并将其显示在网站上。
简单的 HTML、CSS 和 vanilla JS
所以我想保持 repo 公开并使用 GitHub Pages 托管站点......但我的 js 文件包含运行时所需的 API 密钥。
(所有这些都是我搜索时发现的)
我知道有一种方法可以将 API 密钥保存在 GitHub 机密中,然后在 yml 文件中将其作为 GitHub Actions 中的环境变量引用。但是如何在运行时为访问我网站的任何用户将该秘密放入 js 代码中?
openweathermap ×10
android ×4
json ×4
weather-api ×4
java ×3
javascript ×3
api ×1
api-key ×1
buildconfig ×1
github-pages ×1
google-maps ×1
html ×1
retrofit ×1
retrofit2 ×1
weather ×1