fiz o seguinte codigo para pegar a longitude e latitude com o endereço… so q esta caindo no catch com este erro "Invalid byte 2 of 2-byte UTF-8 sequence.’
meu codigo ficou asim
alguem poderia me ajudar?
[code]package com.controlmobile.util;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import com.controlmobile.entity.LongitudeLatitude;
public class SearchLongLat {
public LongitudeLatitude getLongLat(String address) {
try {
String thisLine;
address = address.replace(' ', '+');
URL u = new URL(
"http://maps.google.com/maps/geo?q=\'"
+ address
+ "\'&output=xml&ABQIAAAA-p9H5A-4ByAkCnGpnWvmVRSZBikiXOrbbl0eyFwjsYfXLs5q5hRqCRL35w0zeDa-5m96RVKojxlhhA");
LongitudeLatitude longitudeLatitude = new LongitudeLatitude();
BufferedReader theHTML = new BufferedReader(new InputStreamReader(
u.openStream()));
FileWriter fstream = new FileWriter("url.xml");
BufferedWriter out = new BufferedWriter(fstream);
while ((thisLine = theHTML.readLine()) != null)
out.write(thisLine);
out.close();
File file = new File("url.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
NodeList nl = doc.getElementsByTagName("code");
Element n = (Element) nl.item(0);
String st = n.getFirstChild().getNodeValue();
if (st.equals("200")) {
NodeList n2 = doc.getElementsByTagName("coordinates");
Element nn = (Element) n2.item(0);
String longLat = nn.getFirstChild().getNodeValue();
String[] list = longLat.split(";");
for (String longLatUN : list) {
String[] content = longLatUN.split(",");
longitudeLatitude.setLatitude(Double.parseDouble(content[0]));
longitudeLatitude.setLongitude(Double.parseDouble(content[1]));
}
return longitudeLatitude;
} else {
return null;
}
} catch (MalformedURLException e) {
System.out.println("error 1 ="+e.getMessage());
return null;
} catch (IOException e) {
System.out.println("error 2 ="+e.getMessage());
return null;
} catch (Exception ex) {
System.out.println("error 3 =" + ex.getMessage());
return null;
}
}
}
[/code]