How to use marker's coordinates as variables at Unfolding

Hello people, I'm new to Unfolding and Processing as well, I've been looking through the tutorials at the Unfolding page and everything seems to work fine, so my problem is that I want to create a variable marker (so it can change its location as it runs), I thought of just changing the coordinates in the location to a float type variables but it seems that I'm forgetting something or someting like that.

I would really apreciate your help even though I'm sure it's pretty dumb.

Here's the code I've been trying to run

import de.fhpotsdam.unfolding.*;
  import de.fhpotsdam.unfolding.geo.*;
  import de.fhpotsdam.unfolding.utils.*;
  import de.fhpotsdam.unfolding.marker.*;
  import de.fhpotsdam.unfolding.providers.Google;

UnfoldingMap map;

void setup() {
  size(800, 600);
  map = new UnfoldingMap(this, new Google.GoogleMapProvider());
  MapUtils.createDefaultEventDispatcher(this, map);
  float Lat=8.27;
  float Lon=-62.73;
}

void draw() { 
    map.draw();

    Location berlinLocation = map.getLocation(Lat, Lon);
    Marker berlinMarker = new SimplePointMarker(berlinLocation);
    map.addMarker(berlinMarker);

    Location location = map.getLocation(mouseX, mouseY);
    fill(0);
    text(location.getLat() + ", " + location.getLon(), mouseX, mouseY);

}

Answers

  • Answer ✓

    Variables Lat & Lon exist only inside setup() b/c they were declared there! :-SS
    If you need them to be accessed everywhere, place their declaration outside any function:

    import de.fhpotsdam.unfolding.*;
    
    UnfoldingMap map;
    float Lat = 8.27, Lon = -62.73;
    
    void setup() {
    

    BtW in Java's conventions, variables should start w/ lowercase letters:

    float lat = 8.27, lon = -62.73;
    

    However, if they're supposed to be constant or immutable values, they should be fully capitalized:

    static final float LAT = 8.27, LON = -62.73;
    
  • That solve my problem nicely, thank you very much!

Sign In or Register to comment.