現在、私は Android Studio に地図の写真を持っています。どうすれば wunderground から情報を取得して、各場所の地図の上に表示できるのか疑問に思っていました。
これは、いくつかのサンプル コードを含む Web サイトです。
現在、私は Android Studio に地図の写真を持っています。どうすれば wunderground から情報を取得して、各場所の地図の上に表示できるのか疑問に思っていました。
これは、いくつかのサンプル コードを含む Web サイトです。
それはデータの種類によって異なります。JSON フィードから地震データの場所を取得する例を考えてみましょう。
try {
JSONObject object = (JSONObject) new JSONTokener(JSONResponse)
.nextValue();
JSONArray earthquakes = object.getJSONArray("features");
for (int i = 0; i < earthquakes.length(); i++) {
JSONObject tmp = (JSONObject) earthquakes.get(i);
//Log.i("JSON: ",tmp.toString());
JSONObject geometry = tmp.getJSONObject("geometry");
JSONArray coords = geometry.getJSONArray("coordinates");
JSONObject properties = tmp.getJSONObject("properties");
//Log.i("Data", "Coords:"+coords.getString(0) + " "+ coords.getString(1)+"\n Place:"+properties.getString("place")+ " Mag:"+properties.getString("mag"));
if(coords.getString(0) != "" && coords.getString(1) != ""){
result.add(new EarthQuakeRec(
Float.parseFloat(coords.getString(1)),//Lat
Float.parseFloat(coords.getString(0)),//Long
Float.parseFloat(properties.getString("mag")),//Magnitude
properties.getString("place")
)
);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
JSON 構造は次のようになります。
{
"id": "nc72241526",
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-122.0102,
37.6053,
6
]
},
"properties": {
"detail": "http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72241526.geojson",
"type": "earthquake",
"net": "nc",
"tsunami": null,
"sources": ",nc,",
"title": "M 3.0 - 1km NE of Union City, California",
"time": 1403371328500,
"updated": 1403374699020,
"mag": 3,
"types": ",dyfi,focal-mechanism,general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,tectonic-summary,",
"place": "1km NE of Union City, California",
"status": "AUTOMATIC",
"ids": ",nc72241526,",
"alert": null,
"rms": 0.17,
"code": "72241526",
"url": "http://earthquake.usgs.gov/earthquakes/eventpage/nc72241526",
"magType": "Md",
"mmi": null,
"cdi": 3.8,
"tz": -420,
"felt": 319,
"nst": 75,
"dmin": 0.03593261,
"gap": 25.2,
"sig": 260
}
}
次に、JSONObject クラスから始めて、関心のあるデータ ポイントにドリルダウンします。Log クラスを使用して、トラブルシューティングを行い、データ構造のトラバースの進行状況を評価します。私の例では、コメントアウトされています。
XMLの場合、これに合わせて何かを試すことができます:
try {
// Create the Pull Parser
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
// Set the Parser's input to be the XML document in the HTTP Response
xpp.setInput(new InputStreamReader(response.getEntity()
.getContent()));
// Get the first Parser event and start iterating over the XML document
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
startTag(xpp.getName());
} else if (eventType == XmlPullParser.END_TAG) {
endTag(xpp.getName());
} else if (eventType == XmlPullParser.TEXT) {
text(xpp.getText());
}
eventType = xpp.next();
}
return mResults;
} catch (XmlPullParserException e) {
e.printStackTrace();
}
あなたに投げかけることはたくさんありますが、あなたはあまり具体的ではありませんでした. それが役立つことを願っています。;)