Created
May 5, 2012 03:29
-
-
Save vbugarsk/2599379 to your computer and use it in GitHub Desktop.
create google maps polyline from gpx file $_GET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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