5

Đôi khi tôi gặp Service Not Available Trường hợp ngoại lệ trong đơn đăng ký của mình. Hầu hết thời gian, không có vấn đề gì. Nhưng đôi khi điều đó xảy ra. (Ứng dụng vẫn đang được phát triển)Mã hóa địa lý đảo ngược - Dịch vụ Không khả dụng - Khởi động lại thiết bị không giải quyết dứt khoát - chỉ trích mã hóa địa lý nghịch đảo thủ công của tôi

Cách duy nhất để giải quyết là khởi động lại thiết bị cầm tay. Relevant Issue38009 on support forums. Nhưng những gì tôi hiểu từ các ý kiến ​​là việc khởi động lại thiết bị sẽ giải quyết vấn đề mãi mãi.

Điều này có đúng không?
Vì trong trường hợp của tôi, lỗi có thể trở lại (tần suất: một lần hoặc hai lần một tháng tôi nghĩ rằng & Tôi toàn thời gian trên ứng dụng này).

cách để khởi động lại trình mã hóa địa lý từ bên trong ứng dụng?

Giải pháp duy nhất tôi có là cung cấp giải pháp thay thế chỉ trong trường hợp tìm nạp "thủ công" địa chỉ như dưới đây. Bạn có tốt hơn không?

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; 
+0

Liên kết của bạn phải được trỏ tới đây: https://code.google.com/p/android/issues/detail?id=38009 Từ khi tôi đọc sự cố, _no_, việc khởi động lại không giải quyết được sự cố vĩnh viễn. –

+0

thực sự, sửa nó. – Poutrathor

Trả lời

0

liên kết từ @ Mike trạng thái: một thực hiện dự phòng sử dụng Geocoder handler và AsyncTask lớp cả hai cần phải được đồng bộ - như thế nào nếu không có dịch vụ chúng tôi có thể nhận được địa chỉ từ URL. Đây là giải pháp duy nhất chúng tôi có thể cung cấp không may @Poutrathor.

Tham khảo ở đây Service not Available - Geocoder Android

Ngoài ra chúng tôi không thể ép buộc người dùng phải khởi động lại nhưng ít nhất thông báo cho một giải pháp về nó.

+1

Xin chào! liên kết của bạn không thành công, đóng theo cách này: [Dịch vụ không khả dụng - Geocoder Android] (liên kết) – Poutrathor

+0

cảm ơn! @Poutrathor – MOSO