2

I am trying to get the latidute and the longitude from the URL. My current code:

public void getCoordinate(String city) {
    try {
        URL current = new URL("https://google.de/maps/place/" + city);
        URLConnection currentConnection = current.openConnection();

        System.out.println("Current: " + current.toString());

        Thread.sleep(180 * 40L);

        URL updated = currentConnection.getURL();

        System.out.println("Now: " + updated.toString());

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

My idea: I call the side with the City i want and after a few seconds, i get the new URL which contains the longitude and the latitude. When i try it manually, i do this steps:

  1. Insert the URL with the given City
  2. Wait a few seconds and the URL changes
  3. Use the new URL to work with it

My problem is, I don't know, how to get the updated URL.

pogibas
  • 27,303
  • 19
  • 84
  • 117
Simagdo
  • 87
  • 1
  • 8
  • It kind of works. But not as i want. Here is an example: URL i create: https://www.google.de/maps/place/Dortmund/ The URL i want to get: https://www.google.de/maps/place/Dortmund/@51.5078011,7.3301801,11z/data=!3m1!4b1!4m5!3m4!1s0x47b91760bff07a11:0x427f28131548750!8m2!3d51.5135872!4d7.4652981 The output of the method you suggested: orignal url: https://google.de/maps/place/Dortmund connected url: https://google.de/maps/place/Dortmund redirected url: https://www.google.de/maps/place/Dortmund?dg=dbrw&newdg=1 – Simagdo Oct 21 '17 at 11:20

0 Answers0