TiandituSearch.java
2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.pashanhoo.landsurvey.search;
import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.JSONObjectRequestListener;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
public class TiandituSearch {
private static ArrayList<POISuggestion> poiSuggestionArrayList = new ArrayList<POISuggestion>();
public static ArrayList<POISuggestion> getPoi(String name){
String str = "{\"keyWord\":\"" + name + "\",\"level\":\"11\",\"mapBound\":" +
"\"76.24832,30.1129,156.40458,49.97618\",\"queryType\":\"1\",\"count\":\"10\"" +
",\"start\":\"0\",\"queryTerminal\":\"1000\"}";
AndroidNetworking.post("http://map.tianditu.com/query.shtml")
.addBodyParameter("type", "query")
.addBodyParameter("postStr", str)
.setTag("test")
.build()
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("pois");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject Jasonobject = jsonArray.getJSONObject(i);
poiSuggestionArrayList.add(new POISuggestion(Jasonobject.getString("name"),
Jasonobject.getString("address"),
Jasonobject.getString("lonlat")));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ANError anError) {
poiSuggestionArrayList = null;
}
});
return poiSuggestionArrayList;
}
}