
Originariamente inviata da
andbin
Mah, il punto semmai è un altro: da DOVE arriva una stringa come Viale della Libertà , 9 con una à chiaramente "sballata" e inappropriata?
Problemi di encoding/charset?
Da questo codice per la trasformazione delle coordinate in indirizzo, interrogando google maps
codice:
protected String readLocationFeed(String coords) throws IOException
{
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
//System.out.println("http://maps.google.com/maps/api/geocode/json?latlng=" + coords + "&sensor=false");
HttpGet httpGet = new HttpGet("http://maps.google.com/maps/api/geocode/json?latlng=" + coords + "&sensor=false");
try
{
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200)
{
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null)
{
builder.append(line);
}
}
else
{
System.err.println("Failed to download file");
}
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return builder.toString();
}
/**
* Analizza l'oggetto JSON delle API di localizzazione geografica al fine di trovare l'indirizzo completo corrispondente
* alle coordinate passate come parametro
* @param lat latitudine della geolocalizzazione
* @param lon longitudine della geolocalizzazione
* @return stringa contenente l'indirizzo corrispondente alle coordinate
* @throws IOException
* @author ashrith
*/
protected String getLocation(String lat, String lon) throws IOException
{
String location = null;
String readUserFeed = readLocationFeed(lat.trim() + "," +lon.trim());
try
{
JSONObject strJson = (JSONObject) JSONValue.parse(readUserFeed);
JSONArray jsonArray = (JSONArray) strJson.get("results");
JSONObject jsonAddressComp = (JSONObject)jsonArray.get(0);
location = jsonAddressComp.get("formatted_address").toString();
//Rimuoviamo eventuali accento
location = location.replace('à', 'a');
location = location.replace("Ã", "a");
location = location.replace('è', 'e');
location = location.replace('é', 'e');
location = location.replace('ì', 'i');
location = location.replace('ò', 'o');
location = location.replace('ù', 'u');
}
catch (Exception e)
{
e.printStackTrace();
}
//System.out.println("Location: " +location);
return location;
}