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 xlocate.properties these samples may not work properly.
<h2>An error occurred while executing the request.</h2>
<p><b>Message: </b><%=message%></p>
<% } %>
<%
}
%>
</body>
</html>
<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java"
import="java.io.*"
import="java.util.*"
import="com.ptvag.jabba.service.baseservices.*"
import="com.ptvag.xserver.common.*"
import="com.ptvag.xserver.xlocate.*"
import="com.ptvgroup.xserver.framework.*"
%>
<%
{
//
// This page is a sample for PTV xLocate 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", "50020");
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/XLocate";
//
// 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:50020/xlocate/ws/XLocate";
String serviceUrl = url;
//
// The request parameters are defined here
//
// The search address
String country = "L";
String state = "";
String postCode = "";
String city = "Wellenstein";
String city2 = "";
String street = "Rue de la Moselle";
String houseNumber = "5";
// The profile to be used
String profile = "default";
// The coordinate-format to be used
String coordFormat = CoordFormat.PTV_GEODECIMAL.getValue();
//
// Building the request
//
// Address element
Address address = new Address();
address.setCountry(country);
address.setState(state);
address.setPostCode(postCode);
address.setCity(city);
address.setCity2(city2);
address.setStreet(street);
address.setHouseNumber(houseNumber);
// CallerContext element to set co-ordinate format and profile name
CallerContext callerContext = new CallerContext();
callerContext.setLog1("xLocate sample 1");
callerContext.setLog2("");
callerContext.setLog3("");
CallerContextProperty p1 = new CallerContextProperty("CoordFormat", coordFormat);
CallerContextProperty p2 = new CallerContextProperty("ResponseGeometry", GeometryEncoding.PLAIN.getValue());
CallerContextProperty p3 = new CallerContextProperty("Profile", profile);
CallerContextProperty[] callerContextProperties = {p1, p2, p3};
callerContext.setProperties(callerContextProperties);
//
// Creating the service instance
//
// Use JWSDP or CXF? => Check what's available...
RemoteType remoteType = null;
try {
Class.forName("com.ptvag.xserver.xlocate.XLocateCXFClient");
// => CXF available
remoteType = RemoteType.DOCSTYLE_CXF;
} catch(Exception e) {
// => JWSDP
remoteType = RemoteType.DOCSTYLE_JWSDP;
}
XLocateRemoteInterface client = (XLocateRemoteInterface) ClientFactory.createClient(XLocateRemoteInterface.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.xlocate.AddressResponse addressResponse = null;
try
{
addressResponse = client.findAddress(address, null, null, null);
}
catch (Exception e)
{
success = false;
message = e.toString();
}
if (success == true && addressResponse == 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 response
// addresses are displayed, otherwise the error message is displayed.
%>
<% if (success == true) {
// Build a table from the result list
%>
<h2>The request has been executed successfully.</h2>
<p>The input address has been geocoded with the following result:</p>
<p>Error code: <%=addressResponse.getErrorCode()%>, error description: <%=addressResponse.getErrorDescription()%></p>
<table border="1">
<tr>
<th>Country</th>
<th>State</th>
<th>Postal code</th>
<th>City</th>
<th>City2</th>
<th>Street</th>
<th>House number</th>
<th>x co-ordinate</th>
<th>y co-ordinate</th>
<th>Total score</th>
</tr>
<% if (addressResponse.getResultList() != null)
{
for (int i = 0; i < addressResponse.getResultList().length; i++)
{
%>
<tr>
<td><%=addressResponse.getResultList()[i].getCountry()%></td>
<td><%=addressResponse.getResultList()[i].getState()%></td>
<td><%=addressResponse.getResultList()[i].getPostCode()%></td>
<td><%=addressResponse.getResultList()[i].getCity()%></td>
<td><%=addressResponse.getResultList()[i].getCity2()%></td>
<td><%=addressResponse.getResultList()[i].getStreet()%></td>
<td><%=addressResponse.getResultList()[i].getHouseNumber()%></td>
<td><%=addressResponse.getResultList()[i].getCoordinates().getPoint().getX()%></td>
<td><%=addressResponse.getResultList()[i].getCoordinates().getPoint().getY()%></td>
<td><%=addressResponse.getResultList()[i].getTotalScore()%></td>
</tr>
<%
}
}
%>
</table>
<% } else { %>
<h2>An error occurred while executing the request.</h2>
<p><b>Message: </b><%=message%></p>
<% } %>
<%
}
%>
</body>
</html>
Sample 2: Find the address closest to a given location
This sample shows how to find the address which is closest to a given location.
By default the search is tolerant. If the is more than one address close to the given location,
all addresses are returned. They are ordered by distance.
Jsp Sample
View the source by clicking 'show/hide source' below, or execute it by clicking execute.
<h2>An error occurred while executing the request.</h2>
<p><b>Message: </b><%=message%></p>
<% } %>
<%
}
%>
</body>
</html>
<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java"
import="java.io.*"
import="java.util.*"
import="com.ptvag.jabba.service.baseservices.*"
import="com.ptvag.xserver.common.*"
import="com.ptvag.xserver.xlocate.*"
import="com.ptvgroup.xserver.framework.*"
%>
<%
{
//
// This page is a sample for PTV xLocate 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", "50020");
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/XLocate";
//
// 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:50020/xlocate/ws/XLocate";
String serviceUrl = url;
//
// The request parameters are defined here
//
// The search location
int x = 612976;
int y = 4960956;
// The profile to be used
String profile = "default";
// The coordinate-format to be used
String coordFormat = CoordFormat.PTV_GEODECIMAL.getValue();
//
// Building the request
//
// Location element
Location location = new Location();
location.setCoordinate(new Point());
location.getCoordinate().setPoint(new PlainPoint());
location.getCoordinate().getPoint().setX(x);
location.getCoordinate().getPoint().setY(y);
// CallerContext element to set co-ordinate format and profile name
CallerContext callerContext = new CallerContext();
callerContext.setLog1("xLocate sample 2");
callerContext.setLog2("");
callerContext.setLog3("");
CallerContextProperty p1 = new CallerContextProperty("CoordFormat", coordFormat);
CallerContextProperty p2 = new CallerContextProperty("ResponseGeometry", GeometryEncoding.PLAIN.getValue());
CallerContextProperty p3 = new CallerContextProperty("Profile", profile);
CallerContextProperty[] callerContextProperties = {p1, p2, p3};
callerContext.setProperties(callerContextProperties);
//
// Creating the service instance
//
// Use JWSDP or CXF? => Check what's available...
RemoteType remoteType = null;
try {
Class.forName("com.ptvag.xserver.xlocate.XLocateCXFClient");
// => CXF available
remoteType = RemoteType.DOCSTYLE_CXF;
} catch(Exception e) {
// => JWSDP
remoteType = RemoteType.DOCSTYLE_JWSDP;
}
XLocateRemoteInterface client = (XLocateRemoteInterface) ClientFactory.createClient(XLocateRemoteInterface.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.xlocate.AddressResponse addressResponse = null;
try
{
addressResponse = client.findLocation(location, null, null, null);
}
catch (Exception e)
{
success = false;
message = e.toString();
}
if (success == true && addressResponse == 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 response
// addresses are displayed, otherwise the error message is displayed.
%>
<% if (success == true) {
// Build a table from the result list
%>
<h2>The request has been executed successfully.</h2>
<p>The input address has been reversely geocoded with the following result:</p>
<p>Error code: <%=addressResponse.getErrorCode()%>, error description: <%=addressResponse.getErrorDescription()%></p>
<table border="1">
<tr>
<th>Country</th>
<th>State</th>
<th>Postal code</th>
<th>City</th>
<th>City2</th>
<th>Street</th>
<th>House number</th>
<th>x co-ordinate</th>
<th>y co-ordinate</th>
</tr>
<% if (addressResponse.getResultList() != null)
{
for (int i = 0; i < addressResponse.getResultList().length; i++)
{
%>
<tr>
<td><%=addressResponse.getResultList()[i].getCountry()%></td>
<td><%=addressResponse.getResultList()[i].getState()%></td>
<td><%=addressResponse.getResultList()[i].getPostCode()%></td>
<td><%=addressResponse.getResultList()[i].getCity()%></td>
<td><%=addressResponse.getResultList()[i].getCity2()%></td>
<td><%=addressResponse.getResultList()[i].getStreet()%></td>
<td><%=addressResponse.getResultList()[i].getHouseNumber()%></td>
<td><%=addressResponse.getResultList()[i].getCoordinates().getPoint().getX()%></td>
<td><%=addressResponse.getResultList()[i].getCoordinates().getPoint().getY()%></td>
</tr>
<%
}
}
%>
</table>
<% } else { %>
<h2>An error occurred while executing the request.</h2>
<p><b>Message: </b><%=message%></p>
<% } %>
<%
}
%>
</body>
</html>
Sample 3: Find points of interest
This sample shows how to query for points of interest closest to a given postal address.
Jsp Sample
View the source by clicking 'show/hide source' below, or execute it by clicking execute.
<h2>An error occurred while executing the request.</h2>
<p><b>Message: </b><%=message%></p>
<% } %>
<%
}
%>
</body>
</html>
<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java"
import="java.io.*"
import="java.util.*"
import="com.ptvag.jabba.service.baseservices.*"
import="com.ptvag.xserver.common.*"
import="com.ptvag.xserver.xlocate.*"
import="com.ptvgroup.xserver.framework.*"
%>
<%
{
//
// This page is a sample for PTV xLocate 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", "50020");
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/XLocate";
//
// 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:50020/xlocate/ws/XLocate";
String serviceUrl = url;
//
// The request parameters are defined here
//
// The search address
String country = "L";
String state = "";
String postCode = "";
String city = "Luxembourg";
String city2 = "";
String street = "";
String houseNumber = "";
String poiName = "";
// poi type, see documentation for a list of available poi types
String poiType = "7311";
// The profile to be used
String profile = "default";
// The coordinate-format to be used
String coordFormat = CoordFormat.PTV_GEODECIMAL.getValue();
//
// Building the request
//
// Address element
PoiAddress address = new PoiAddress();
address.setCountry(country);
address.setState(state);
address.setPostCode(postCode);
address.setCity(city);
address.setCity2(city2);
address.setStreet(street);
address.setHouseNumber(houseNumber);
address.setPoiName(poiName);
address.setPoiType(poiType);
// CallerContext element to set co-ordinate format and profile name
CallerContext callerContext = new CallerContext();
callerContext.setLog1("xLocate sample 3");
callerContext.setLog2("");
callerContext.setLog3("");
CallerContextProperty p1 = new CallerContextProperty("CoordFormat", coordFormat);
CallerContextProperty p2 = new CallerContextProperty("ResponseGeometry", GeometryEncoding.PLAIN.getValue());
CallerContextProperty p3 = new CallerContextProperty("Profile", profile);
CallerContextProperty[] callerContextProperties = {p1, p2, p3};
callerContext.setProperties(callerContextProperties);
//
// Creating the service instance
//
// Use JWSDP or CXF? => Check what's available...
RemoteType remoteType = null;
try {
Class.forName("com.ptvag.xserver.xlocate.XLocateCXFClient");
// => CXF available
remoteType = RemoteType.DOCSTYLE_CXF;
} catch(Exception e) {
// => JWSDP
remoteType = RemoteType.DOCSTYLE_JWSDP;
}
XLocateRemoteInterface client = (XLocateRemoteInterface) ClientFactory.createClient(XLocateRemoteInterface.class, remoteType, "","", serviceUrl);
client.setCallerContext(callerContext);
// Set user and password
client.setUsername("sample222");
client.setPassword("sample");
//
// Sending the request
//
String message = "";
boolean success = true;
com.ptvag.xserver.xlocate.PoiAddressResponse addressResponse = null;
try
{
addressResponse = client.findPoiByAddress(address, null, null, null);
}
catch (Exception e)
{
success = false;
message = e.toString();
}
if (success == true && addressResponse == 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 response
// addresses are displayed, otherwise the error message is displayed.
%>
<% if (success == true) {
// Build a table from the result list
%>
<h2>The request has been executed successfully.</h2>
<p>The poi search has yielded the following result:</p>
<p>Error code: <%=addressResponse.getErrorCode()%>, error description: <%=addressResponse.getErrorDescription()%></p>
<table border="1">
<tr>
<th>Country</th>
<th>Poi name</th>
<th>Poi type</th>
<th>x co-ordinate</th>
<th>y co-ordinate</th>
<th>Postal code</th>
<th>City</th>
<th>Street</th>
<th>House number</th>
</tr>
<% if (addressResponse.getResultList() != null)
{
for (int i = 0; i < addressResponse.getResultList().length; i++)
{
%>
<tr>
<td><%=addressResponse.getResultList()[i].getCountry()%></td>
<td><%=addressResponse.getResultList()[i].getPoiName()%></td>
<td><%=addressResponse.getResultList()[i].getPoiType()%></td>
<td><%=addressResponse.getResultList()[i].getCoordinates().getPoint().getX()%></td>
<td><%=addressResponse.getResultList()[i].getCoordinates().getPoint().getY()%></td>
<td><%=addressResponse.getResultList()[i].getPostCode()%></td>
<td><%=addressResponse.getResultList()[i].getCity()%></td>
<td><%=addressResponse.getResultList()[i].getStreet()%></td>
<td><%=addressResponse.getResultList()[i].getHouseNumber()%></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.