Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 反向地理编码-服务不可用-重新启动设备无法最终解决-批评我的手动反向地理编码_Android_Reverse Geocoding_Google Geocoder_Service Not Available - Fatal编程技术网

Android 反向地理编码-服务不可用-重新启动设备无法最终解决-批评我的手动反向地理编码

Android 反向地理编码-服务不可用-重新启动设备无法最终解决-批评我的手动反向地理编码,android,reverse-geocoding,google-geocoder,service-not-available,Android,Reverse Geocoding,Google Geocoder,Service Not Available,我时常遇到应用程序中的服务不可用异常。大多数时候,没有问题。但有时也会发生。(该应用程序仍在开发中) 唯一的解决方法是重新启动手机。但我从评论中了解到,重新启动设备可以永远解决问题 这是正确的吗? 因为在我的情况下,bug可能会再次出现(频率:我想一个月一次或两次&我在这个应用程序上是全职的) 是否有方法从应用程序内部重新启动地理编码器 我唯一的解决方案是提供一个替代方案,以防“手动”获取下面这样的地址。有更好的吗 Dbg.d(TAG, "=== address_info FetchLo

我时常遇到应用程序中的
服务不可用
异常。大多数时候,没有问题。但有时也会发生。(该应用程序仍在开发中)

唯一的解决方法是重新启动手机。但我从评论中了解到,重新启动设备可以永远解决问题

这是正确的吗?
因为在我的情况下,bug可能会再次出现(频率:我想一个月一次或两次&我在这个应用程序上是全职的)

是否有方法从应用程序内部重新启动地理编码器

我唯一的解决方案是提供一个替代方案,以防“手动”获取下面这样的地址。有更好的吗

    Dbg.d(TAG, "=== address_info FetchLocationTask - doInBackground");
new Thread(new Runnable() {

    @Override
    public void run() {
        Looper.prepare();
        mHandler = new Handler();
        Looper.loop();
    }
}).start();

    /**
     * Implementation of a second method in case of failure:
     * 
     */
    double lat = Double.parseDouble(args[0]);
    double lng = Double.parseDouble(args[1]);
    String address = String.format(Locale.ENGLISH,
            "http://maps.googleapis.com/maps/api/geocode/json?latlng="+Double.toString(lat)+","+Double.toString(lng)+"&sensor=true&language="+Locale.getDefault().getCountry(), lat, lng);
    Dbg.d(TAG, "fetching path : "+ address);


    HttpGet httpGet = new HttpGet(address);
    HttpClient client = new DefaultHttpClient();
    HttpResponse response;
    StringBuilder stringBuilder = new StringBuilder();

    List<Address> retList = null;

    try {
        response = client.execute(httpGet);
        HttpEntity entity = response.getEntity();
        InputStream stream = entity.getContent();
        int b;
        while ((b = stream.read()) != -1) {
            stringBuilder.append((char) b);
        }

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


        retList = new ArrayList<Address>();


        if("OK".equalsIgnoreCase(jsonObject.getString("status"))){
            JSONArray results = jsonObject.getJSONArray("results");
            for (int i=0;i<results.length();i++ ) {
                JSONObject result = results.getJSONObject(i);
                String indiStr = result.getString("formatted_address");
                Address addr = new Address(Locale.ITALY);
                addr.setAddressLine(0, indiStr);
                Dbg.d(TAG, "adresse :"+addr.toString());
                retList.add(addr);
            }
        }


    } catch (ClientProtocolException e) {
        Dbg.e(TAG, "Error calling Google geocode webservice.", e);
    } catch (IOException e) {
        Dbg.e(TAG, "Error calling Google geocode webservice.", e);
    } catch (JSONException e) {
        Dbg.e(TAG, "Error parsing Google geocode webservice response.", e);
    }

    JSONObject jObj = new JSONObject();

    boolean found = false;

    if (retList.size() > 0) {

        Address a = retList.get(0);

        String name = a.getAddressLine(0);
        String city = a.getLocality();
        String postalCode = a.getPostalCode();
        String country = a.getCountryName();

        if (!TextUtils.isEmpty(name)) {
            JsonUtils.setSringInJson(jObj, BookLocation.ADDRESS_NAME_KEY, name);
            found = true;
        }
        if (!TextUtils.isEmpty(postalCode)) {
            JsonUtils.setSringInJson(jObj, BookLocation.ADDRESS_POSTAL_CODE_KEY, postalCode);
            found = true;
        }
        if (!TextUtils.isEmpty(city)) {
            JsonUtils.setSringInJson(jObj, BookLocation.ADDRESS_CITY_KEY, city);
            found = true;
        }
        if (!TextUtils.isEmpty(country)) {
            JsonUtils.setSringInJson(jObj, BookLocation.ADDRESS_COUNTRY_KEY, country);
            found = true;
        }

    }
    mHandler.getLooper().quit();
    if (found) {
        return jObj;
    } else return null;
Dbg.d(标记,”==address\u info FetchLocationTask-doInBackground);
新线程(newrunnable()){
@凌驾
公开募捐{
Looper.prepare();
mHandler=新处理程序();
loop.loop();
}
}).start();
/**
*在故障情况下实施第二种方法:
* 
*/
double lat=double.parseDouble(args[0]);
double lng=double.parseDouble(args[1]);
字符串地址=String.format(Locale.ENGLISH,
"http://maps.googleapis.com/maps/api/geocode/json?latlng=“+Double.toString(lat)+”,“+Double.toString(lng)+”&sensor=true&language=“+Locale.getDefault().getCountry(),lat,lng);
Dbg.d(标记,“获取路径:”+地址);
HttpGet HttpGet=新的HttpGet(地址);
HttpClient=new DefaultHttpClient();
HttpResponse响应;
StringBuilder StringBuilder=新的StringBuilder();
List-retList=null;
试一试{
response=client.execute(httpGet);
HttpEntity=response.getEntity();
InputStream=entity.getContent();
int b;
而((b=stream.read())!=-1){
stringBuilder.append((char)b);
}
JSONObject JSONObject=新的JSONObject();
jsonObject=新的jsonObject(stringBuilder.toString());
retList=newarraylist();
if(“OK”.equalsIgnoreCase(jsonObject.getString(“status”)){
JSONArray results=jsonObject.getJSONArray(“结果”);
对于(int i=0;i 0){
地址a=retList.get(0);
字符串名称=a.getAddressLine(0);
字符串city=a.getLocation();
字符串postalCode=a.getPostalCode();
字符串country=a.getCountryName();
如果(!TextUtils.isEmpty(名称)){
JsonUtils.setstringinjson(jObj,BookLocation.ADDRESS\u NAME\u KEY,NAME);
发现=真;
}
如果(!TextUtils.isEmpty(postalCode)){
JsonUtils.setstringinjson(jObj,BookLocation.ADDRESS,邮政编码,邮政编码);
发现=真;
}
如果(!TextUtils.isEmpty(城市)){
JsonUtils.setstringinjson(jObj,BookLocation.ADDRESS\u CITY\u KEY,CITY);
发现=真;
}
如果(!TextUtils.isEmpty(国家)){
JsonUtils.setstringinjson(jObj,BookLocation.ADDRESS\u COUNTRY\u KEY,COUNTRY);
发现=真;
}
}
mHandler.getLooper().quit();
如果(找到){
返回jObj;
}否则返回null;

来自@mike的链接指出:使用GeoCoder处理程序和asynctask类的回退实现都需要同步-就像如果没有服务,我们可以从URL获取地址一样。 不幸的是,这是我们能提供的唯一解决方案@Poutrathor

参考这里


此外,我们不能强制用户重新启动,但至少要告知解决方案。

您的链接应该指向此处:从我对问题的理解来看,不,重新启动并不能永久解决问题。您好!您的链接已失败,请通过以下方式关闭:[服务不可用-Geocoder Android](链接)