ich Funktion haben, die geben mir lat lange von Adresse:Geokodierung: Wie OVER_QUERY_LIMIT in google map api -java vermeiden
public static String[] getLatLongPositions(String address) throws Exception
{
int responseCode = 0;
String api = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + URLEncoder.encode(address, "UTF-8") + "&sensor=true";
//System.out.println("URL : "+api);
URL url = new URL(api);
HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();
httpConnection.connect();
responseCode = httpConnection.getResponseCode();
if(responseCode == 200)
{
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();;
Document document = builder.parse(httpConnection.getInputStream());
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("/GeocodeResponse/status");
String status = (String)expr.evaluate(document, XPathConstants.STRING);
if(status.equals("OK"))
{
expr = xpath.compile("//geometry/location/lat");
String latitude = (String)expr.evaluate(document, XPathConstants.STRING);
expr = xpath.compile("//geometry/location/lng");
String longitude = (String)expr.evaluate(document, XPathConstants.STRING);
return new String[] {latitude, longitude};
}
else
{
throw new Exception("Error from the API - response status: "+status+"street "+ address);
}
}
return null;
}
Aber sehr oft bekomme ich OVER_QUERY_LIMIT i Schlaf so versuchen, für einen Moment und meine Funktion erneut aus diese Zugabe:
if(status.equals("OVER_QUERY_LIMIT")){
Thread.sleep(1000);
getLatLongPositions(address);
}
Aber wenn getLatLongPositions wieder rekursiv ausgeführt i null steigen Sie an dieser Linie responseCode = httpConnection.getResponseCode();
Wie kann ich vermeiden, dieses Problem? Auch in dieser Funktion sind einige Adressen ohne Fehler, aber wenn ich diese Funktion erneut ausführen bekomme ich Fehler mit diesen Adressen, die vorher gut waren. Diese