Using PTV xMapmatch Server with Java/Jsp and C#

Overview

If you have accessed this page through the xServer's management console, you can immediately view and execute the Jsp code samples, just click the links below. Refer to the troubleshooting section if the samples do not work. This page is best viewed with Mozilla Firefox.

In order to install the C# samples which are not displayed here by default, refer to the C# installation section.

These samples are designed to be executed with the default data of Luxemburg. If you changed the data path in xmapmatch.properties these samples may not work properly.

Use case samples

Please choose an xMapmatch sample use case

Sample 1: Match track with some 5 seconds intervalls

This sample shows how to match a track with 5 seconds intervalls with some TrackPositions which are derived from NMEA-Tracks or other GPS signal representations.

For further information on the parameters used please refer to matchTrack() in the API documentation.

Jsp Sample

View the source by clicking 'show/hide source' below, or execute it by clicking execute.
<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java"  
	import="java.io.*" 
	import="java.util.*" 
	import="java.text.*" 
	import="com.ptvag.jabba.service.baseservices.*" 
	import="com.ptvag.xserver.common.*" 
	import="com.ptvag.xserver.xmapmatch.*" 
	import="com.ptvgroup.xserver.framework.*" 
%>
<%!
	public Calendar[] getFiveSecondIntervalls(int sizeOfArray) {

		Calendar[] calendar = new Calendar[sizeOfArray];
		
		Calendar cal = Calendar.getInstance();
		calendar[0] = cal;
		long timeInMillis = cal.getTimeInMillis();
		int fiveSeconds = 5000;

		
		for (int i = 1; i < sizeOfArray; i++) {
			timeInMillis += fiveSeconds;
			cal = Calendar.getInstance();
			cal.setTimeInMillis(timeInMillis);
			calendar[i] = cal;
		}
		return calendar;
	}
%>
<%
{
	//
	// This page is a sample for PTV xMapmatch Server and is intended to
	// show client developers how to request information from the server.
	// See the code comments for documentation.
	//
	// Please note that the default url is http://localhost:<port>/<service>.
	//

	// The xServer's port
	String port = System.getProperty("port.http", "50040");
	String path = this.getServletContext().getRealPath("/").replace('\\', '/');

	// Build up the xServer's service url
	String url = request.getRequestURL().toString().split(":")[0] + "://localhost:" + port + "/" + path.substring(path.lastIndexOf("webapps") + 8) + "ws/XMapmatch";

	//
	// When using this sample in a different context, i.e. not within the xServer, 
	// please uncomment and modify the following line and comment the line following that line.
	//
	//String serviceUrl = "http://localhost:50040/xmapmatch/ws/XMapmatch";
	String serviceUrl = url;


	//
	// The request parameters are defined here
	//
	TrackPosition[] positions = new TrackPosition[23];
	Calendar[] cal = getFiveSecondIntervalls(23);
	int k = 0;
	
	positions[k] = new TrackPosition(1, 251.06f, 5.0004f, cal[k++], new Double(6.11467), new Double(49.626195), null);
	positions[k] = new TrackPosition(10, 251.06f, 5.0004f, cal[k++], new Double(6.11408), new Double(49.626065), null);
	positions[k] = new TrackPosition(20, 162.05f, 5.0004f, cal[k++], new Double(6.1138566666), new Double(49.625745), null);
	positions[k] = new TrackPosition(30, 147.06f, 5.0004f, cal[k++], new Double(6.11411), new Double(49.62533), null);
	positions[k] = new TrackPosition(40, 148.97f, 5.0004f, cal[k++], new Double(6.114455), new Double(49.62494), null);
	positions[k] = new TrackPosition(50, 148.97f, 5.0004f, cal[k++], new Double(6.1148133333), new Double(49.624555), null);	
	positions[k] = new TrackPosition(60, 154.08f, 5.00004f, cal[k++], new Double(6.1151466666), new Double(49.6241616666), null);		
	positions[k] = new TrackPosition(80, 144.25f, 5.00004f, cal[k++], new Double(6.1159333333), new Double(49.6234233333), null);		
	positions[k] = new TrackPosition(110, 144.52f, 5.00004f, cal[k++], new Double(6.1167416666), new Double(49.622691666), null);		
	positions[k] = new TrackPosition(120, 147.06f, 5.00004f, cal[k++], new Double(6.1174366666), new Double(49.621915), null);		
	positions[k] = new TrackPosition(140, 142.56f, 5.00004f, cal[k++], new Double(6.11825), new Double(49.621186666), null);		
	positions[k] = new TrackPosition(160, 130.61f, 5.00004f, cal[k++], new Double(6.11901), new Double(49.620435), null);		
	positions[k] = new TrackPosition(190, 130.61f, 5.00004f, cal[k++], new Double(6.12063), new Double(49.61958833), null);		
	positions[k] = new TrackPosition(210, 108.65f, 5.00004f, cal[k++], new Double(6.12172666), new Double(49.6190533), null);		
	positions[k] = new TrackPosition(250, 126.75f, 5.00004f, cal[k++], new Double(6.12413166), new Double(49.6181983), null);		
	positions[k] = new TrackPosition(300, 235.21f, 8.00007f, cal[k++], new Double(6.12363666), new Double(49.615935), null);		
	positions[k] = new TrackPosition(330, 211.54f, 8.00007f, cal[k++], new Double(6.12111166), new Double(49.614615), null);		
	positions[k] = new TrackPosition(380, 180f, 8.00007f, cal[k++], new Double(6.118216), new Double(49.611551666), null);		
	positions[k] = new TrackPosition(400, 153.50f, 8.00007f, cal[k++], new Double(6.11893333), new Double(49.610215), null);		
	positions[k] = new TrackPosition(430, 167.81f, 8.00007f, cal[k++], new Double(6.119795), new Double(49.60814), null);		
	positions[k] = new TrackPosition(460, 180f, 8.00007f, cal[k++], new Double(6.11973), new Double(49.60599333), null);		
	positions[k] = new TrackPosition(480, 163.51f, 8.00007f, cal[k++], new Double(6.120248333), new Double(49.60460333), null);		
	positions[k] = new TrackPosition(510, 197.95f, 8.00007f, cal[k++], new Double(6.120353333), new Double(49.60252666), null);	
	
	// The profile to be used
	String profile = "default";
	
	// The map to be used
	String mapname = "lux_d";

	//
	// Building the request
	//

	// CallerContext element to set co-ordinate format and profile name
	CallerContext callerContext = new CallerContext(); 
	callerContext.setLog1("xMapmatch sample 1"); 
	callerContext.setLog2(""); 
	callerContext.setLog3(""); 
	CallerContextProperty p1 = new CallerContextProperty("Profile", profile); 
	CallerContextProperty[] callerContextProperties = {p1}; 
	callerContext.setProperties(callerContextProperties); 

	
	//
	// Creating the service instance
	//
	
    // Use JWSDP or CXF? => Check what's available...
    RemoteType remoteType = null;
    try {
        Class.forName("com.ptvag.xserver.xmapmatch.XMapmatchCXFClient");
        // => CXF available
        remoteType = RemoteType.DOCSTYLE_CXF;
    } catch(Exception e) {  
        // => JWSDP
        remoteType = RemoteType.DOCSTYLE_JWSDP;
    }
    
    XMapmatchRemoteInterface client = (XMapmatchRemoteInterface) ClientFactory.createClient(XMapmatchRemoteInterface.class, remoteType, "","", serviceUrl);

	client.setCallerContext(callerContext);
	
	// Set user and password
	client.setUsername("sample");
	client.setPassword("sample");

	//
	// Sending the request
	//

	String message = "";
	boolean success = true;
	com.ptvag.xserver.xmapmatch.MatchResult result = null;

	try 
	{
		result = client.matchTrack(positions, "lux_d");
	}
	catch (Exception e) 
	{
		success = false;
		message = e.toString();
	}

	if (success == true && result == null)
	{
		success = false;
		message = "Error parsing the response.";
	}

%>
<html> 
    <head>
        <meta http-equiv="Content-Language" content="en-us">
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
        <title>PTV xServer - Code Samples</title>
        <link rel="shortcut icon" href="../images/favicon.ico"/>
        <link type="text/css" rel="stylesheet" href="../css/xserver.css">
    </head>
<body>

<%
	// If the request has been executed successfully, the complete path and the matched 
	// locations are displayed.
%>

<% if (success == true) {
        // Build a table from the result list
%>

<h2>The request has been executed successfully.</h2>
<p>The input positions has been matched with the following result:</p>
  
<% 	if (result.getCompletePath() != null && result.getCompletePath().length >= 1) {
        %>
			<b>Complete Path</b>
			<table border="1">
			  <tr>
				<th>Country code</th>
				<th>Length</th>
				<th>Speed Limit Forward</th>
				<th>Routing Segment Index</th>
				<th>Tile Id</th>
			  </tr> 
	    <%
		for (int i = 0; i < result.getCompletePath().length; i++) {
			%>
			<tr>
				<td><%=result.getCompletePath()[i].getCountryCode()%></td> 
				<td><%=result.getCompletePath()[i].getLength()%></td>
				<td><%=result.getCompletePath()[i].getSpeedLimitForward()%></td>
				<td><%=result.getCompletePath()[i].getRtgSegIdx()%></td>
				<td><%=result.getCompletePath()[i].getTileId()%></td>
			</tr>
			<%
		} %>
		</table>  
<% } else { %>
    <p><b>There is no Complete Path</b></p> 
<% }
	
%>
</p><b>Matched Locations</b>
<table border="1">
  <tr>
    <th>Input Id</th>
    <th>Latitude </th>
    <th>Longitude </th>
    <th>Heading</th>
    <th>Stable</th>
    <th>Path</th>
  </tr>
  
<%	
	if (result.getCompletePath() != null) {
		for (int i = 0; i < result.getMatchedLocations().length; i++) {
			%>
			<tr>
				<td><%=result.getMatchedLocations()[i].getInputId()%></td> 
				<td><%=result.getMatchedLocations()[i].getLat()%></td>
				<td><%=result.getMatchedLocations()[i].getLon()%></td>
				<td><%=result.getMatchedLocations()[i].getHeading()%></td>
				<td><%=result.getMatchedLocations()[i].getStable()%></td>
				<td>
				<%
				if (result.getMatchedLocations()[i].getPath() != null) {
					for (int j = 0; j < result.getMatchedLocations()[i].getPath().length; j++) {
					MatchedSegment seg = result.getMatchedLocations()[i].getPath()[j];
				    String pathString = "Length= " + seg.getLength() + " SpeedLimitForward = " + seg.getSpeedLimitForward() 
					   + " TileId=" +  seg.getTileId() + " RtgSegIdx=" + seg.getRtgSegIdx();
					%>
					<%=pathString%></br>
					<%
					}
				}
				%>
				</td>
			</tr>
			<%
		}
	}	
%>
</table>


<% } else { %>

<h2>An error occurred while executing the request.</h2>
<p><b>Message: </b><%=message%></p>

<% } %>

<% 
} 
%>

</body> 
</html> 

Troubleshooting

If the Jsp samples cannot be executed, please view the source code and check the serviceUrl variable.

C# installation

The C# samples can be found in the xServer's samples folder. Please unpack them into the root folder of your local IIS installation, usually C:\Inetpub\wwwroot. Then call the IIS management console from the Control Panel and register the samples.

Additionally make sure, that Microsoft.Net Framework 2.0 redistributables are installed and ASP.NET is registered within Internet Information Services (IIS). For registration use the ASP.NET IIS Registration tool with the command line

aspnet_regiis.exe -i

After having executed these steps, please reload this page. The C# samples are automatically displayed and can be executed.

Please note: If your IIS installation directory is not C:\Inetpub\wwwroot, then edit this page and change the value of the IISPath variable. If the IIS url is not http://localhost then change the value if the IISUrl variable.