# Can't seem to map latitude and longitude coordinates correctly in Processing 3

**URL:** <https://discourse.processing.org/t/cant-seem-to-map-latitude-and-longitude-coordinates-correctly-in-processing-3/734>\
**Category:** Coding Questions\
**Created:** [June 5, 2018, 6:17pm UTC](https://discourse.processing.org/t/cant-seem-to-map-latitude-and-longitude-coordinates-correctly-in-processing-3/734 "2018-06-05T18:17:23Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![Reconfigured](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@Reconfigured](https://discourse.processing.org/u/Reconfigured)\
**Post date:** [May 12, 2019, 6:22am UTC](https://discourse.processing.org/t/cant-seem-to-map-latitude-and-longitude-coordinates-correctly-in-processing-3/734/9 "2019-05-12T06:22:27Z")

</div>

Hi All,

I’m attempting to adapt some of the provided examples above to draw lines between the points in my XML data.

Here’s a sample of my XML data

```auto
<dataPoint>
		<id>474781744</id>
		<timestamp>7/12/2012 3:01</timestamp>
		<longitude>147.388981</longitude>
		<latitude>-36.356586</latitude>
	</dataPoint>
	<dataPoint>
		<id>474781745</id>
		<timestamp>7/12/2012 3:31</timestamp>
		<longitude>147.390586</longitude>
		<latitude>-36.3578</latitude>
	</dataPoint>

```

And here’s what I’ve come up with for my sketch:

```auto
gpsPoint[] gpsPoints1;

XML xml;

PImage background;

float mapScreenWidth, mapScreenHeight;

void setup() {
  size(3840, 2160);
  background(255);
  xml = loadXML("sheepData_001.xml");
  background = loadImage("img/paddock.png");
  mapScreenWidth = width;
  mapScreenHeight = height;
  image(background, 0, 0, mapScreenWidth, mapScreenHeight);
  smooth();
  
  XML[] point = xml.getChildren("dataPoint");
  
  

  for (int i = 0; i < point.length; i++) {
    XML idElement = point[i].getChild("id");
    int event = idElement.getIntContent();
    
    XML timeElement = point[i].getChild("timestamp");
    String time = timeElement.getContent();
    
    XML longElement = point[i].getChild("longitude");
    float longitude = longElement.getFloatContent();
    
    XML latElement = point[i].getChild("latitude");
    float latitude = latElement.getFloatContent();
    
    println(event + "," + time + "," + longitude + "," + latitude);
  
  
    
  
    gpsPoints1 = new gpsPoint[point.length];
  
    for (int a = 0; a < point.length-1; a++){
      
      XML longData1 = point[a].getChild("longitude");
      float pointLong1 = longData1.getFloatContent();
      
      XML longData2 = point[a+1].getChild("longitude");
      float pointLong2 = longData2.getFloatContent();
      
      XML latData1 = point[a].getChild("latitude");
      float pointLat1 = latData1.getFloatContent();
      
      XML latData2 = point[a+1].getChild("latitude");
      float pointLat2 = latData2.getFloatContent();
  
      float mainx = map(pointLong1, 147.3538, 147.3922, 0, width);
      float mainy = map(pointLat1, -36.3228, -36.3179, 0, height);
      float mainx2 = map(pointLong2, 147.3538, 147.3922, 0, width);
      float mainy2 = map(pointLat2, -36.3228, -36.3179, 0, height);
      
      gpsPoints1[a] = new gpsPoint(mainx, mainy, mainx2, mainy2);
      gpsPoints1[a].display();
    }
    
  }
  println("num of points " + point.length);
}
void draw() {  
}

class gpsPoint {

  float prevX;
  float prevY;
  float newX;
  float newY;

  gpsPoint(float previousX, float previousY, float nextX, float nextY){
    prevX = previousX;
    prevY = previousY;
    newX = nextX;
    newY = nextY;
  }
  
  
  void display() {
    stroke(0);
    strokeWeight(2);
    point(prevX, prevY);
    line(prevX, prevY, newX, newY);
  }
}

```

It seems to function okay, but the lines I’m getting don’t seem to fully represent the point data that I get by removing all of the secondary point grabbing and go back to just plotting lines from the data.

 ![pointsLines](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bf5a05a25f0f5b0d827ee276d6527370fceb8b81.jpeg)  
This image is a side by side of the points and then lines I’m getting.

Anyone notice anything that I’m doing in my code that would throw my lines off? I know there’s likely a better way to get the secondary points, but it’s working thus far in terms of running.

Thanks in advance

---

_[View the full topic](https://discourse.processing.org/t/cant-seem-to-map-latitude-and-longitude-coordinates-correctly-in-processing-3/734)._
