private void Timer(ActionEvent evt) {
    // TODO Auto-generated method stub
    try {
      int minBus = 110;
      int maxBus = 120;
      double minAfkLat = 42.302;
      double maxAfkLat = 42.304;
      System.out.println("Timer");
      timer.stop();
      MapMarker init = new MapMarker(theLatitude, theLongitude);
      String theMapURIAsString =
          (String) MapLookup.getMap(theLatitude, theLongitude, init).substring(0, 87);
      int testint2 = 0;
      for (Listener l : theListeners) {
        // if(l.Latitude != 9999 && Float.parseFloat(l.BusID.split("#")[1]) < maxBus &&
        // Float.parseFloat(l.BusID.split("#")[1]) > minBus)    //Bussar beroende på buss nummer
        // if(l.Latitude != 9999 && l.Latitude > minAfkLat && l.Latitude < maxAfkLat)
        // //Possible afk busses
        // if(l.Latitude != 9999 && ( l.Latitude < minAfkLat || l.Latitude > maxAfkLat))
        // //Exclude afk busses
        if (l.Latitude != 9999.0) // All busses
        {
          theMapURIAsString += "|";
          theMapURIAsString += Float.toString(l.Latitude) + "," + Float.toString(l.Longitude);
        }
      }
      theMapURIAsString += "&sensor=false&key=AIzaSyBR_wUAQ3iPM2e8WeoQIUw9c3xLJPRGZL8";
      // System.out.println("HEIR COWMES F****R\n" + theMapURIAsString + "\nFUCKER IS COMMEN");

      String[] GetRidOfinitMarker = theMapURIAsString.split("42.358543,-71.096178\\|");
      // String[] GetRidOfinitMarker = theMapURIAsString.split("42.303113,-71.109925\\|"); //afk
      // bussar
      String GottenRidOfinitMarker = GetRidOfinitMarker[0] + GetRidOfinitMarker[1];

      String test = theMapURIAsString.split("&markers=")[1];
      String[] testa = test.split("\\|");
      // for(String v : testa)System.out.println(v);  //alla inkomna positioner
      // Retrieve map from Google Maps.
      // URL theMapURI = new URL(theMapURIAsString);
      URL theMapURI = new URL(GottenRidOfinitMarker); // URL Utan init marker
      theMap = ImageIO.read(theMapURI.openStream());

      // Create map image scaled to size of the application window size.
      imagePanel1.setImage(
          theMap.getScaledInstance(
              imagePanel1.getWidth(), imagePanel1.getHeight(), Image.SCALE_AREA_AVERAGING));

      // Display map image.
      imagePanel1.repaint();
    } catch (Exception ex) {
      timer.start();
    }
    timer.start();
  }
Esempio n. 2
0
  // Goes online to get user authentication from Flickr.
  public void getAuthentication() {
    AuthInterface authInterface = flickr.getAuthInterface();

    try {
      frob = authInterface.getFrob();
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      URL authURL = authInterface.buildAuthenticationUrl(Permission.WRITE, frob);

      // open the authentication URL in a browser
      open(authURL.toExternalForm());
    } catch (Exception e) {
      e.printStackTrace();
    }

    println("You have 15 seconds to approve the app!");
    int startedWaiting = millis();
    int waitDuration = 15 * 1000; // wait 10 seconds
    while ((millis() - startedWaiting) < waitDuration) {
      // just wait
    }
    println("Done waiting");

    try {
      auth = authInterface.getToken(frob);
      println("Authentication success");
      // This token can be used until the user revokes it.
      token = auth.getToken();
      // save it for future use
      saveToken(token);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // complete authentication
    authenticateWithToken(token);
  }