+ -
当前位置:首页 → 问答吧 → MapView 的 getFromLocationName, 模糊范围的搜寻

MapView 的 getFromLocationName, 模糊范围的搜寻

时间:2011-09-30

来源:互联网

Greeting ,
我可以使用 Google map 定位自己的位置,使用 MapView , 也会跟者人移到而一起移动

作者: shanchieh   发布时间: 2011-09-30

刚刚我做一个测试,使用 Google map api 来达到我要的功能,程式码:

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
public class MapUtility {
  public static JSONObject getLocationInfo(String address) {
 
    HttpGet httpGet = new HttpGet("http://maps.google."
 
    + "com/maps/api/geocode/json?address=" + address
 
    + "&sensor=false");
 
    HttpClient client = new DefaultHttpClient();
 
    HttpResponse response;
 
    StringBuilder stringBuilder = new StringBuilder();
 
    try {
 
      response = client.execute(httpGet);
 
      HttpEntity entity = response.getEntity();
 
      InputStream stream = entity.getContent();
 
      int b;
 
      while ((b = stream.read()) != -1) {
 
        stringBuilder.append((char) b);
 
      }
 
    } catch (ClientProtocolException e) {
 
      e.printStackTrace();
 
    } catch (IOException e) {
 
      e.printStackTrace();
 
    }
 
    JSONObject jsonObject = new JSONObject();
 
    try {
 
      jsonObject = new JSONObject(stringBuilder.toString());
 
    } catch (JSONException e) {
 
      e.printStackTrace();
 
    }
 
    return jsonObject;
 
  }
 
  // converts JSONObject into a GeoPoint.
 
  public static GeoPoint getGeoPoint(JSONObject jsonObject) {
 
    Double lon = new Double(0);
 
    Double lat = new Double(0);
 
    try {
 
      lon = ((JSONArray) jsonObject.get("results")).getJSONObject(0)
 
      .getJSONObject("geometry").getJSONObject("location")
 
      .getDouble("lng");
 
      lat = ((JSONArray) jsonObject.get("results")).getJSONObject(0)
 
      .getJSONObject("geometry").getJSONObject("location")
 
      .getDouble("lat");
 
    } catch (JSONException e) {
 
      e.printStackTrace();
 
    }
 
    return new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));
 
  }
}


这是可以执行,但是查出来的结果一样很怪,他使用 map 查询

作者: shanchieh   发布时间: 2011-09-30

热门下载

更多