coordinates Data to pixels

edited June 2016 in Questions about Code

I try to get the longitude and latitude of the earth quack on the map but i get a weird values, can someone help me figure out what i'm doing wrong?

I get the following values, which are outside my canvas:

Example of the Json data:

Answers

  • (when posting code just highlight it and press ctrl-o. you are currently posting it as a quote which is much less readable)

  • @ Koogs i've edited the code. thanks for the hint

  • (it also works for data...)

  •  float lan_begin = -13.0; // Longtitude start (largest longitude value)
     float lan_eind = -25.0; // Longtitude end (smallest longitude value)
     float lon_begin = 66.8;  // Latitude start (largest latitude value)
     float lon_eind = 63.1; // Latitude end (smallest latitude value)
    

    ...

    float x = map(latitude, lan_eind, lan_begin, 0, 1000 );
    float y = map(longitude, lon_eind, lon_begin, 0, 800);
    

    lan_begin = longitude start but you're comparing latitude against it when setting x...

  • edited June 2016

    with map i try to get the value of the pixel on the canvas using the latitude/longitude i get from the Json file and the latitude and longitude of Iceland.

    when i change the lantitude and the longitude to -180,180 and -90,90 i get the following vallues, but there are @ the same arae:

    680.0611,324.95554
    681.1806,327.1289
    681.1806,327.12
    681.1778,327.11554
    684.72504,322.2311
    684.2055,317.2311
    676.825,314.88
    681.01666,327.8089
    681.0417,327.88446
    678.87775,322.93335
    682.50275,325.46664
    677.6639,311.12
    677.64996,311.11554
    682.51666,325.29333
    677.5305,302.17776
    676.67773,314.93777
    676.79443,313.88446
    679.19165,321.72
    678.49445,308.87555
    683.51385,322.45334
    677.0083,296.68
    676.67224,295.95554
    676.69446,314.9867
    677.3444,299.9289
    676.8472,296.6489
    679.7278,324.52
    676.81665,314.71558
    676.80835,315.1511
    680.0445,324.99557
    683.6528,321.48444
    679.1861,321.34222
    680.03613,324.98666
    677.7139,314.03998
    677.4055,301.79556
    679.71387,322.5422
    681.05835,327.66223
    676.74164,314.77332
    676.80554,314.6667
    
  • Answer ✓

    did you change these lines?

    float x = map(latitude, lan_eind, lan_begin, 0, 1000 );
    float y = map(longitude, lon_eind, lon_begin, 0, 800);
    

    because i think they need to be

    float x = map(longitude, lan_eind, lan_begin, 0, 1000 );
    float y = map(latitude, lon_eind, lon_begin, 0, 800);
    

    (swapping the longitude (east-west) and latitude (north-south))

  • @ Koogs thank you very much. it works now ;)

Sign In or Register to comment.