Hallo Leute, ich habe folgendes Problem :
Ich habe ein Programm das mir die Lat/Lng von einer PLZ sagt, das Programm bzw. der Code ist richtig, jedoch bekomme ich immer am Ende diese Fehlermeldung :
Das ist mein Programm vielleicht hilfts euch:
Ich habe ein Programm das mir die Lat/Lng von einer PLZ sagt, das Programm bzw. der Code ist richtig, jedoch bekomme ich immer am Ende diese Fehlermeldung :
Code:
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:852)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:793)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:718)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
at java.net.URL.openStream(URL.java:1009)
at Geocode.getLocation(Geocode.java:39)
at Geocode.main(Geocode.java:15)
Das ist mein Programm vielleicht hilfts euch:
Java:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
public class Geocode {
private final static String ENCODING = "UTF-8";
private final static String KEY = "ABQIAAAAGJfPF1hEw2RqMWN7d2EV7BT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQCKSuRrDfiJWA1thA53PDaHe2wyA";
public static void main(String[] arg) throws Throwable{
Geocode.getLocation("46117");
System.out.println("Test");
}
public static class Location {
public String lon, lat;
private Location(String lat, String lon) {
this.lon = lon;
this.lat = lat;
}
public String toString() {
return "Lat: " + lat + ", Lon: " + lon;
}
}
public static Location getLocation(String address) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(new URL(
"http://maps.google.com/maps/geo?q="
+ URLEncoder.encode(address, ENCODING)
+ "&output=csv&key=" + KEY).openStream()));
String line;
Location location = null;
int statusCode = -1;
while ((line = in.readLine()) != null) {
// Format: 200,6,42.730070,-73.690570
statusCode = Integer.parseInt(line.substring(0, 3));
if (statusCode == 200)
location = new Location(line.substring("200,6,".length(), line
.indexOf(',', "200,6,".length())), line.substring(line
.indexOf(',', "200,6,".length()) + 1, line.length()));
}
if (location == null) {
switch (statusCode) {
case 400:
throw new IOException("Bad Request");
case 500:
throw new IOException("Unknown error from Google Encoder");
case 601:
throw new IOException("Missing query");
case 602:
return null;
case 603:
throw new IOException("Legal problem");
case 604:
throw new IOException("No route");
case 610:
throw new IOException("Bad key");
case 620:
throw new IOException("Too many queries");
}
}
return location;
}
}