Thursday 28 October 2010

MapMyFitness JSON API Example




function loadMaps() {
var type = 2; //bike ride
var radius = 10;
$.ajax({
type: 'GET',
url: "http://api.mapmyfitness.com/3/routes/search_routes?&o=json&user_id=&user_key=&keyword=&min_latitude=51.08786&max_latitude=51.38786&min_longitude=-0.3013&max_longitude=-0.3013&center_longitude=51.38786&center_latitude=-0.3013&center_geocode=&radius=" + radius + "&route_type_id=" + type + "&city=&state=&country_code=&zip=&start_record=0&limit=25&sort_by=featured_flag%20desc,%20average_rating%20desc,%20route_name",
data: "id=" + "&lang=en-us&format=json&jsoncallback=?",
success: function(feed) {
// Create an empty array to store images
var thumbs = [];

// Loop through the items
for (var i = 0, l = feed.result.output.routes.length; i < l && i < 16; ++i) {
var routename = feed.result.output.routes[i].route_name;
// Add the new element to the array
thumbs.push(routename);
}

// Display the routes on the page
$('#feed').html(thumbs.join(''));

var show_user = tmpl("item_tmpl"), html = "";

for (var ii = 0; ii < feed.result.output.routes.length; ii++) {
html += show_user(feed.result.output.routes[ii]);
}
//var results = document.getElementById("results");
$('#vcalendar').html(html);
},
dataType: 'jsonp'
});
}