GPX bounds element

The GPX file has a very convenient element called bounds which defines the bounding box of all of the tracks defined in the GPX file. Here is a sample:

<gpx ...>

This elements allows you to quickly find where to center your map and also allows you to draw a bounding box around track. Without this element you would need to find the min. and the max lat. and long. of all the track points in the GPX file.

Here is a JavaScript function to create a bounding box (using Google Map API) around the track (the $ notation (Perl) means the value of these variables on the server where you’re creating the JavaScript):

function createBoundingBox() {
       var box= [];
       box.push(new GPoint($minlon, $maxlat));
       box.push(new GPoint($maxlon, $maxlat));
       box.push(new GPoint($maxlon, $minlat));
       box.push(new GPoint($minlon, $minlat));
       box.push(new GPoint($minlon, $maxlat));
       map.addOverlay(new GPolyline(box));

Google API also includes class GBounds that allows you to create a bounding box object and has methods to find the intersection of two bounding boxes, if a point is included in a bounding box, etc. You can create a GBounds object using the GPX bounds elements, e.g.,

var bounds = new GBounds($minlon, $minlat, $maxlon, $maxlat);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: