Skip to content

Instantly share code, notes, and snippets.

@vbugarsk
Created May 5, 2012 03:29
Show Gist options
  • Save vbugarsk/2599379 to your computer and use it in GitHub Desktop.
Save vbugarsk/2599379 to your computer and use it in GitHub Desktop.
create google maps polyline from gpx file $_GET
$.ajax({
type: "GET",
url: "URL to the GPX file",
dataType: "xml",
success: function(xml) {
var points = [];
var bounds = new google.maps.LatLngBounds ();
$(xml).find("trkpt").each(function() {
var lat = $(this).attr("lat");
var lon = $(this).attr("lon");
var p = new google.maps.LatLng(lat, lon);
points.push(p);
bounds.extend(p);
});
var poly = new google.maps.Polyline({
// use your own style here
path: points,
strokeColor: "#FF00AA",
strokeOpacity: .7,
strokeWeight: 4
});
poly.setMap(map);
// fit bounds to track
map.fitBounds(bounds);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment