Transportation Mode API

This API provides automatic segmentation and transportation mode detection. It supports both GET and POST request types, however, the post variant is recommended to use because trajectories typically have a large number of points that often exceed the capacity of the GET method.

Input:
URL: https://cs.uef.fi/mopsi/routes/transportationModeApi/api.php
Parameters: param containing a JSON description of the request.
JSON attributes:


Output:
A JSON Array where each element, describing one segment, has the following attributes:

The example JavaScript code below loads a sample GPS trajectory from here and calls the POST variant of the API to find out the transportation mode.

						var TRANSPORTATION_MODE_SERVER=
	"http://cs.uef.fi/mopsi/routes/transportationModeApi/api.php";
	
processRouteFromTxtFile("data/route.txt");

function computeTransportationMode(route){
	var param={
		"request_type":"segment_route",
		"route":route
	}
	//
	httpPost(TRANSPORTATION_MODE_SERVER,
		"param="+JSON.stringify(param),
		processResponse);
}

function processResponse(jsonString){
	// outputing to console
	console.log(jsonString);
}

function httpPost(url, dataString, callback){
	var request = new XMLHttpRequest();
	request.open('POST', url, true);
	request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	request.onreadystatechange = function() { 
        if (request.readyState == 4 && request.status == 200){
            callback(request.responseText);
		}
    }
	request.send( dataString );
}

function processRouteFromTxtFile(file){
	httpPost(file,"",function(stringFormat){
		var route=parseRouteTxt(stringFormat);
		computeTransportationMode(route);
	});
}

function parseRouteTxt(stringFormat){
	var points=stringFormat.split("\n");
	var route=new Array();
	for(var i = 0;i<=points.length-1;i++){
		var components=points[i].split(" ");
		route.push({
			lat:(Number)(components[0]),
			lng:(Number)(components[1]),
			time:(Number)(components[2])
		});
	}
	return route;
}