Java Geocoding Tool

shitake83

Mitglied
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 :

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;
	}
}
 
mhn doch nicht... bei mir klappts...

Die Verwendung des Google Geocoding API unterliegt einem Abfragelimit von 2,500 Geolokalisierungsanforderungen pro Tag.
wie oft hast den das heute schon probiert? 🙂

eventuell liegts an einer firewall oder so..

klappt das:

Java:
 public static void printUrlContent(String urlString) throws Exception {
         URLConnection con = new URL(urlString).openConnection();
         con.connect();
         BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
         String line = null;
         while ((line = reader.readLine()) != null) {
            System.out.println(line);
         }
         
   }
mit zb. Java programmieren aus Leidenschaft und mit ... mhn http://maps.google.com/maps/geo?q=mondsee&output=csv
 
Danke für die schnelle Antwort.
Aber google müsste eigentlich antworten, wenn ich die URL per hand eingebe die mein Prog erzeugt kriege ich ein Ergebnis.
 
Nein die maximale Anzhal an Abfragen hab ich heute noch net durch 🙂

Soll ichs damit mal testen ? oder was meinst du jetzt ?? steh grad auffem schlauch
 
mhn ja.. vielleicht kommt nur die jvm nicht raus...

versuch das

Java:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class KommIchRaus {


   public static void main(String[] args) throws Exception {
    System.out.println("java forum geht");
      printUrlContent("http://www.java-forum.org");
      
      System.out.println("geht google auch...?");
      printUrlContent("http://maps.google.com/maps/geo?q=5310&output=csv");
      
      

   }

   public static void printUrlContent(String urlString) throws Exception {
         URLConnection con = new URL(urlString).openConnection();
         con.connect();
         BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
         String line = null;
         while ((line = reader.readLine()) != null) {
            System.out.println(line);
         }
         
   }
}
 
Anscheinend gehts nicht :/ ich werd verrückt

Java:
java forum geht
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.[url]www.http.HttpClient.openServer(HttpClient.java:394[/url])
	at sun.net.[url]www.http.HttpClient.openServer(HttpClient.java:529[/url])
	at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
	at sun.net.[url]www.http.HttpClient.New(HttpClient.java:306[/url])
	at sun.net.[url]www.http.HttpClient.New(HttpClient.java:323[/url])
	at sun.net.[url]www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:852[/url])
	at sun.net.[url]www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:793[/url])
	at sun.net.[url]www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:718[/url])
	at KommIchRaus.printUrlContent(KommIchRaus.java:22)
	at KommIchRaus.main(KommIchRaus.java:11)
 
naja is ja nicht tragisch, dan liegts nicht an google sondern deine jvm kommt nicht raus.. vielleicht durch eine firewall blockiert? slitzt du in der schule? da habt ihr sicher einen proxy..

Java:
 Properties properties = System.getProperties();
      properties.put("http.proxyHost", "deineProxyUr.de");
      properties.put("http.proxyPort", "8080");
 
Ja ich bin auf der Arbeit und sitze in einem Netz, das könnte sein das er da nicht wirklich was zurückkriegt.

Wo würde ich das denn einfügen ?? Also in welcher Klasse.
 
Ich habs jetzt hingekriegt. Ich hatte die Falsche IP von unserem Proxy Server.

Dank dir ^^.

Habe als Antwort einmal den Quellcode der Javaforum seite und die Daten aus der CSV
Ergo: Alles funzt.
 

Zurück
Oben