loadStrings

edited July 2016 in How To...

Hello guys, i want to make a program that uses the duration for a route from google maps. But when i use: loadStrings("https://maps.googleapis.com/maps/api/directions/json?origin=München&destination=Berlin&key=AIzaSyDR8I6XTP__cVItDdSAuZxjrQLlpqzIEnc"); the console answers:

java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668) at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173) at sun.net.NetworkClient.doConnect(NetworkClient.java:180) at sun.net.www.http.HttpClient.openServer(HttpClient.java:432) at sun.net.www.http.HttpClient.openServer(HttpClient.java:527) at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264) at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1513) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441) at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338) at processing.core.PApplet.createInputRaw(PApplet.java:6735) at processing.core.PApplet.createInput(PApplet.java:6693) at processing.core.PApplet.loadStrings(PApplet.java:7028) at sketch_160721a.setup(sketch_160721a.java:17) at processing.core.PApplet.handleDraw(PApplet.java:2377) at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1527) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316) The file "https://maps.googleapis.com/maps/api/directions/json?origin=München&destination=Berlin&key=AIzaSyDR8I6XTP__cVItDdSAuZxjrQLlpqzIEnc" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.

the URL is working and the same problem appears when i use www.google.de for example.

Greetings Quirin

Answers

  • edited July 2016

    https://Processing.org/reference/loadJSONObject_.html

    // forum.Processing.org/two/discussion/17607/loadstrings
    // GoToLoop (2016-Jul-21)
    
    static final String HTTPS = "https://";
    static final String SITE = "maps.GoogleAPIs.com";
    static final String FOLDERS = "/maps/api/directions/";
    static final String FILE = "json";
    
    static final String ORIGIN = "origin=M%C3%BCnchen";
    static final String DEST = "destination=Berlin";
    static final String KEY = "key=AIzaSyDR8I6XTP__cVItDdSAuZxjrQLlpqzIEnc";
    
    JSONObject json;
    
    void setup() {
      json = loadJSONObject(
        HTTPS + SITE + FOLDERS + FILE + '?' +
        ORIGIN + '&' + DEST + '&' + KEY);
      println(json);
      exit();
    }
    
  • thanks, but this code gives me the same error.

  • Well, it worked for me. Dunno what else could be the problem. Sorry... :-<

  • i dont think the code is the problem, i tried multiple example codes

  • Well, in my case I had to change "München" to "M%C3%BCnchen" for it to work. L-)

  • yes you are right, i have to change this, but if that was the only problem, your code would have worked, wouldnt it? if there is no problem in the code, maybe the proxyserver is the problem, cause i am at work. i will try it at home and will let you know ;) but thanks anyway for your fast help :)

Sign In or Register to comment.