Od czasu do czasu spotykam się z Service Not Available
Wyjątki w mojej aplikacji. Przez większość czasu nie ma problemu. Ale czasami tak się dzieje. (Aplikacja jest nadal w fazie rozwoju)Odwrotne geokodowanie - Usługa niedostępna - Ponowne uruchomienie urządzenia nie rozwiązuje się definitywnie - krytykuj moje ręczne geokodowanie odwrotne
Jedynym sposobem rozwiązania problemu jest ponowne uruchomienie słuchawki. Relevant Issue38009 on support forums. Ale z komentarzy wynika, że ponowne uruchomienie urządzenia rozwiązuje problem na zawsze.
Czy to prawda? Ponieważ w moim przypadku błąd może powrócić (częstotliwość: raz lub dwa razy w miesiącu Myślę & Jestem w pełnym wymiarze czasu na tej aplikacji).
Czy istnieje sposób ponownego uruchomienia geokodera z poziomu aplikacji?
Jedyne rozwiązanie, jakie mogę zaoferować, to zaproponować alternatywne rozwiązanie, aby pobrać "ręcznie" adres podobny do poniższego. Czy masz coś lepszego?
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;
Twój link powinien wskazywać tutaj: https://code.google.com/p/android/issues/detail?id=38009 Po przeczytaniu problemu, _no_, ponowne uruchomienie nie rozwiązuje na stałe problemu. –
Rzeczywiście, popraw to. – Poutrathor