1

下面是我的代码。对于某些地址,以下代码适用于 Android Device API level-8。但是对于某些地址,地址的值返回为 []。但是从 iphone 调用同一服务器时,我没有遇到这样的问题。

Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
List<Address> address = geocoder.getFromLocationName(MAPADDRESS, 1);

如何在 android 设备中解决此问题。

4

2 回答 2

0

这里的问题是您在查询时只请求一个地址

List<Address> address = geocoder.getFromLocationName(MAPADDRESS, 1);

在这种情况下,Android 将尝试只找到一个地址。您应该提出这个 2 或 3。

也许在第二或第三位置你会获得成功。

将其更改为

List<Address> address = geocoder.getFromLocationName(MAPADDRESS, 3);  
于 2012-06-01T10:11:37.403 回答
0

只需使用以下方法...调用时给出字符串输入

 public static JSONObject getLocationInfo(String address) {
            StringBuilder stringBuilder = new StringBuilder();
            try {

            address = address.replaceAll(" ","%20");    

            HttpPost httppost = new HttpPost("http://maps.google.com/maps/api/geocode/json?address=" + address + "&sensor=false");
            HttpClient client = new DefaultHttpClient();
            HttpResponse response;
            stringBuilder = new StringBuilder();


                response = client.execute(httppost);
                HttpEntity entity = response.getEntity();
                InputStream stream = entity.getContent();
                int b;
                while ((b = stream.read()) != -1) {
                    stringBuilder.append((char) b);
                }
            } catch (ClientProtocolException e) {
            } catch (IOException e) {
            }




            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject = new JSONObject(stringBuilder.toString());


            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


            return jsonObject;
        }
于 2012-06-01T12:23:37.797 回答