I noticed that Geocoder does not work for a month in my app. I tested it different simulator and device. But i never get a address. After test i search another method for find address. While i search this, i notice i am not alone with geocoder issue. Other developers use a work arround. I added a few line of code for encoding UTF-8 characters.
public static List<Address> getStringFromLocation(double lat, double lng) throws ClientProtocolException, IOException, JSONException {
String address = String.format(Locale.ENGLISH, "http://maps.googleapis.com/maps/api/geocode/json?latlng=%1$f,%2$f&sensor=false", lat, lng);
HttpGet httpGet = new HttpGet(address);
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");
HttpResponse response;StringBuilder stringBuilder = new StringBuilder();List<Address> retList = null;JSONObject jsonObject = new JSONObject();response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream stream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));String line;while ((line = reader.readLine()) != null)stringBuilder.append(line);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.getDefault());addr.setAddressLine(0, indiStr);retList.add(addr);}}
return retList;
}
I hope you can use this helpful. And i update Show The Way.
Here is change log;
#2.3
FC Bugs fixed
No location issue solved
Unnecessary dialogs removed
No address issue solved
Reduce ads show
Refactor location code
Library update
If you find my blog or apps usefull, please consider donation.
FC Bugs fixed
No location issue solved
Unnecessary dialogs removed
No address issue solved
Reduce ads show
Refactor location code
Library update
If you find my blog or apps usefull, please consider donation.
Comments
Post a Comment