【问题标题】:Why the addresses returning using Geocoder is different when i run on different devices?为什么当我在不同设备上运行时使用 Geocoder 返回的地址不同?
【发布时间】:2015-03-24 12:43:13
【问题描述】:

我已经在两个不同的设备中测试了以下代码,一个是 4.3,另一个是 4.1.2。4.3 设备给了我地址,而我使用的平板电脑 (4.1.2) 在 getFromLocation().I 中给出了异常不明白为什么两个设备提供两种不同的输出。

Geocoder geocoder = new Geocoder(AAAView.this, Locale.getDefault());
            // Get the current location from the input parameter list
            Location loc = params[0];
            // Create a list to contain the result address
            List<Address> addresses ;
            try {

                lat=loc.getLatitude();
                 lon=loc.getLongitude();

         addresses = geocoder.getFromLocation(lat,lon, 1);

           System.out.println("The address is " + addresses );

            } catch (IOException e1) {
            Log.e("LocationSampleActivity",
                    "IO Exception in getFromLocation() ");
            e1.printStackTrace();
            return ("Cannot get address");
            }

Logcat 错误

03-24 18:51:54.501: W/System.err(12673): java.io.IOException: Service not Available
03-24 18:51:54.509: W/System.err(12673):    at android.location.Geocoder.getFromLocation(Geocoder.java:136)
03-24 18:51:54.509: W/System.err(12673):    at com.assuretech.ku.aaa.AAAView$GetAddressTask.doInBackground(AAAView.java:1070)
03-24 18:51:54.517: W/System.err(12673):    at com.assuretech.ku.aaa.AAAView$GetAddressTask.doInBackground(AAAView.java:1)
03-24 18:51:54.517: W/System.err(12673):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-24 18:51:54.525: W/System.err(12673):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-24 18:51:54.525: W/System.err(12673):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-24 18:51:54.525: W/System.err(12673):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-24 18:51:54.533: W/System.err(12673):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-24 18:51:54.533: W/System.err(12673):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-24 18:51:54.541: W/System.err(12673):    at java.lang.Thread.run(Thread.java:856)

【问题讨论】:

  • 你能把Exception给的帖子贴出来吗?
  • @hrskrs 编辑了我的代码
  • 能否请您重启设备并判断是否同样异常?
  • 是的,我重新启动它工作了..但我听说它会再次发生..?那么有什么永久的解决方案吗??
  • 是的,检查this link 来解决这个问题

标签: android google-geocoder


【解决方案1】:

Geocoding api 依赖于 OS 服务,该服务需要在您进行查询时运行。所以没有服务的设备会抛出异常。

请参阅此处的文档:Geocoder

此外,您可以使用isPresent() 方法来确定该服务是否可用于特定设备。

在这里看看我的回答:Geocoder's isPresent() method always returns false

为了让它正常工作,我建议使用Geocoding api

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2012-01-24
    • 1970-01-01
    • 2015-10-08
    • 2021-04-01
    • 2022-07-06
    • 2016-06-02
    相关资源
    最近更新 更多