# Difficulties with Map Thing and Unfolding (show GPX)

**URL:** https://discourse.processing.org/t/difficulties-with-map-thing-and-unfolding-show-gpx/44188
**Category:** Project Guidance
**Created:** [March 31, 2024, 7:15am UTC](https://discourse.processing.org/t/difficulties-with-map-thing-and-unfolding-show-gpx/44188 "2024-03-31T07:15:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [March 31, 2024, 7:15am UTC](https://discourse.processing.org/t/difficulties-with-map-thing-and-unfolding-show-gpx/44188/1 "2024-03-31T07:15:15Z")

</div>

Hello all,

can someone please recommend a library to show many gpx tracks in a map and calc the middle position of one track?

Thank you all!

---

<div class="post-metadata">

### Author: ![vkbr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vkbr/32/16844_2.png) [@vkbr](https://discourse.processing.org/u/vkbr)
#### Post date: [March 31, 2024, 4:53pm UTC](https://discourse.processing.org/t/difficulties-with-map-thing-and-unfolding-show-gpx/44188/2 "2024-03-31T16:53:19Z")

</div>

> [@Chrisir](#):
>
> can someone please recommend a library to show many gpx tracks in a map and calc the middle position of one track?

As I was just using chatGPT I asked it. Here what it says…  
Not sure if make any sense… : )

> For displaying GPX tracks on a map and calculating the middle position of a track, you can use the following libraries with Processing:
> 
> 1. **Unfolding Maps** : Unfolding Maps is a library for interactive maps and geovisualizations in Processing. It supports various map providers (like OpenStreetMap, Google Maps, Microsoft Bing Maps) and allows you to easily display GPX tracks on the map. You can calculate the middle position of a track by averaging the latitudes and longitudes of all points in the track.
> 2. **GpxParser** : GpxParser is a library specifically designed for parsing GPX files in Processing. While it doesn’t provide direct map visualization capabilities, you can combine it with other mapping libraries like Unfolding Maps or Google Maps for displaying GPX tracks and calculating the middle position.
> 
> Here’s how you can use these libraries for your tasks:
> 
> ### Using Unfolding Maps:
> 
> - **Displaying GPX Tracks** : Unfolding Maps provides examples and documentation on how to load and display GPX tracks. You can use the `LoadGPXTrackApp` example as a reference.
> - **Calculating Middle Position** : Iterate through the GPX track’s waypoints, calculate the average latitude and longitude, and use this as the middle position.
> 
> ### Using GpxParser:
> 
> - **Parsing GPX Files** : Use GpxParser to parse the GPX files and extract waypoint information. Here’s a basic example of how you can use GpxParser:
> 
> javaCopy code
> 
> ```auto
> import de.fhpotsdam.unfolding.geo.Location;
> import de.fhpotsdam.unfolding.utils.GpxUtils;
> 
> void setup() {
> size(800, 600);
> String gpxData = loadStrings("your_track.gpx");
> Location[] locations = GpxUtils.getLocationsFromGpx(this, gpxData);
> // Use locations array to display on map or calculate middle position
> }
> 
> ```
> 
> - **Calculating Middle Position** : Iterate through the `Location` array obtained from GpxParser, calculate the average latitude and longitude, and use this as the middle position.
> 
> Both libraries offer flexibility and ease of use for displaying GPX tracks and performing calculations with them in Processing. Choose the one that best fits your project requirements and preferences.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 1, 2024, 1:07pm UTC](https://discourse.processing.org/t/difficulties-with-map-thing-and-unfolding-show-gpx/44188/3 "2024-04-01T13:07:21Z")

</div>

Thanks  
Unfolding seems to be the best

Can someone show how to load and show an gpx file here?

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [June 15, 2024, 12:40pm UTC](https://discourse.processing.org/t/difficulties-with-map-thing-and-unfolding-show-gpx/44188/4 "2024-06-15T12:40:52Z")

</div>

Hello @vkbr,

> [@vkbr](#):
>
> As I was just using chatGPT I asked it. Here what it says…  
> Not sure if make any sense… : )

It helps to post the question you ask ChatGPT.

The Chat GPT response _at that time_ was not helpful and I found other solutions.

> [@vkbr](#):
>
> `String gpxData = loadStrings("your_track.gpx");`

l_oadStrings()_ returns an array!

> [@vkbr](#):
>
> `Location[] locations = GpxUtils.getLocationsFromGpx(this, gpxData);`

Google Search:  
Your search - _GpxUtils.getLocationsFromGpx_ - did not match any documents.

There was more but I don’t care to revisit this.

ChatGPT can be useful at times but not always.

`:)`

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [June 15, 2024, 12:48pm UTC](https://discourse.processing.org/t/difficulties-with-map-thing-and-unfolding-show-gpx/44188/5 "2024-06-15T12:48:20Z")

</div>

> [@Chrisir](#):
>
> Can someone show how to load and show an gpx file here?

Unfolding has a GPXReader with very basic functionality.

Example:

> [@Give some examples (Unfolding library)](https://discourse.processing.org/t/give-some-examples-unfolding-0-9-6-library-for-javafx/44362/5):
>
> Hello @Ciosiek , This example uses Processing 4.3 library and Unfolding 0.9.92 library and worked in Visual Studio Code 1.88.1: import processing.core.\*; import java.util.List; import de.fhpotsdam.unfolding.UnfoldingMap; import de.fhpotsdam.unfolding.data.Feature; //import de.fhpotsdam.unfolding.geo.Location; import de.fhpotsdam.unfolding.marker.Marker; import de.fhpotsdam.unfolding.utils.MapUtils; import de.fhpotsdam.unfolding.data.GPXReader; //GPX Reader public class App extends PApplet {…

I was also able to write my own custom code from the _GPXReader_ source example and custom parse the JSON files which gave me much more flexibility.

You can also load the GPX files with _loadStrings()_ and parse these for the data you want and plot the tracks.

Reference:  
_[unfolding/src/de/fhpotsdam/unfolding/data/GPXReader.java at master · tillnagel/unfolding · GitHub](https://github.com/tillnagel/unfolding/blob/master/src/de/fhpotsdam/unfolding/data/GPXReader.java)_

> [@Give some examples (Unfolding library)](https://discourse.processing.org/t/give-some-examples-unfolding-library/44362/7):
>
> There is an updated link to Unfolding 0.9.92 here: These worked for me in Processing 4.3 and in Java code (modified for VS Code). slight_smile

`:)`

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 15, 2024, 3:12pm UTC](https://discourse.processing.org/t/difficulties-with-map-thing-and-unfolding-show-gpx/44188/6 "2024-06-15T15:12:30Z")

</div>

Thank you!

my program for this is described here: [What I am working on (my current projects)](https://discourse.processing.org/t/what-i-am-working-on-my-current-projects/44258)

(number 6)
