현재 안드로이드 스튜디오의지도 사진이 있습니다. 그리고 나는 어떻게하면 서라운드에서 정보를 가져 와서 각 위치의지도 위에 표시 할 수 있을지 궁금합니다.Wunderground API에서 데이터를 가져 와서 Android의 화면에 표시하려면 어떻게해야합니까?
This은 몇 가지 샘플 코드가있는 웹 사이트입니다.
현재 안드로이드 스튜디오의지도 사진이 있습니다. 그리고 나는 어떻게하면 서라운드에서 정보를 가져 와서 각 위치의지도 위에 표시 할 수 있을지 궁금합니다.Wunderground API에서 데이터를 가져 와서 Android의 화면에 표시하려면 어떻게해야합니까?
This은 몇 가지 샘플 코드가있는 웹 사이트입니다.
이는 데이터 유형에 따라 달라집니다. JSON 피드에서 eathquake 데이터 위치를 가져 오는 예제를 구성하십시오.
{
"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 클래스를 시작하고 관심있는 데이터 포인트로 드릴 다운 것 :
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 구조는 다음과 같이 보인다. Log 클래스를 사용하면 데이터 구조를 탐색하는 과정에서 문제를 해결하고 진행 상황을 파악하는 데 도움이됩니다. 내 예에서는 주석 처리가되어 있습니다.
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();
}
그것은 당신을 던져 많은,하지만 당신은 많은 특이성을 포기하지 않았다 :
는 XML를 들어, 다음의 조정에 뭔가를 시도 할 수 있습니다. 희망이 도움이됩니다. ;)
JSON, CSV와 같은 어떤 종류의 데이터를 찾고 있습니까? –