Android中谷歌地图v2中的奇怪问题

时间:2014-10-22 14:50:29

标签: android google-maps

我在Stackoverflow和其他论坛上遇到的问题discussed很多,但我有点奇怪。

我在Android上开发了一个谷歌地图v2,昨天工作正常,今天早上我打开地图的应用程序时没有显示地图。我卸载了应用程序并重新生成了地图api的密钥。现在它显示地图但不将地理坐标(纬度,经度)转换为字符串地址并出现异常:

10-22 18:53:14.980: W/System.err(27510): java.io.IOException: Service not Available
10-22 18:53:14.980: W/System.err(27510):    at android.location.Geocoder.getFromLocation(Geocoder.java:136)
10-22 18:53:14.980: W/System.err(27510):    at com.ifahja.map.operations.MapOperation.getLocality(MapOperation.java:138)
10-22 18:53:14.980: W/System.err(27510):    at com.ifahja.map.operations.MapOperation.access$1(MapOperation.java:131)
10-22 18:53:14.980: W/System.err(27510):    at com.ifahja.map.operations.MapOperation$AddLocationAsyncTask.doInBackground(MapOperation.java:38)
10-22 18:53:14.980: W/System.err(27510):    at com.ifahja.map.operations.MapOperation$AddLocationAsyncTask.doInBackground(MapOperation.java:1)
10-22 18:53:14.980: W/System.err(27510):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-22 18:53:14.980: W/System.err(27510):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-22 18:53:14.980: W/System.err(27510):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-22 18:53:14.980: W/System.err(27510):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-22 18:53:14.980: W/System.err(27510):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-22 18:53:14.980: W/System.err(27510):    at java.lang.Thread.run(Thread.java:856)

这是我出现异常的代码片段。

private String getCompleteAddress(Context context,LatLng latLng) {

            Geocoder geocoder = new Geocoder(context);
            double latitude = latLng.latitude;
            double longitude= latLng.longitude; 

            try {
                List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 3);
                String address = addresses.get(0).getAddressLine(0);
                String city = addresses.get(0).getAddressLine(1);
                String country = addresses.get(0).getAddressLine(2);

                String completeAddress = "";

                if(address != null)
                    completeAddress = completeAddress +address+", ";
                if(city != null)
                    completeAddress = completeAddress +city+", ";
                if(country != null)
                    completeAddress = completeAddress +country;
                return completeAddress;

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return "";
        }

注意: 该应用程序昨天工作正常,我用于测试的设备是三星Tab 3 10.1 Android v = 4.2.2

1 个答案:

答案 0 :(得分:0)

重启设备后,现在工作正常。