Accessing PTV xServer internet with PTV client classes

  • While xServer internet uses HTTP basic authentication with <user>/<password>, it is highly recommended to work with the token assigned to your subscription using the combination “xtok”/<token>. Using the token is a safer way than using your far more sensible account data.

  • PTV provides pre-generated assemblies which contain the classes to access xServer internet. For this tutorial you need the xLocate JavaScript client. You have to reference this client-file in your application. Javascript does not have any implicit "import" mechanism but you can set a reference in your html-file.

<script type="text/javascript" src="https://svc-eu-n-test.cloud.ptvgroup.com/xlocate/xlocate-client.js"></script>
  • You can either reference the client directly (as shown above) or download PTV xLocate Javascript client and host it yourself.

    This is a sample for a simple geocoding application and shows how to access the xLocate server.

// enter your token here!
var token = '<INSERT-YOUR-TOKEN-HERE>';
var xtok = 'xtok';
 
// initialize a sample address
var address = {
            "country":"L",
            "postCode": "",
            "city": "Wellenstein",
            "city2": "",
            "street": "Rue de la Moselle 5",
            "houseNumber": ""
                };
 
//initialize a client with the requestURL 
//the requestURL is the base URL of the service to use, before the /rs/ part
var client = new XLocateClient("https://xlocate-eu-n-test.cloud.ptvgroup.com/xlocate");
 
//set credentials and callerContext
client.setCredentials(xtok,token);
client.callerContext= {properties:[{
            "key": "CoordFormat",
            "value": "PTV_MERCATOR"
        }, {
            "key": "Profile",
            "value": "default"
        }]};
 
     
//send a request 
var result = client.findAddress(address,null,null,null,client.callerContext);