Using in JavaScript

GeoTrack provides JavaScript developers with easy to use access to the API through the GeoApi object. It provides authentication handling, asynchronous method calling, error handling.

Download a copy of geoApi.js.

Getting Starting

Reference the file geoApi.js before your main JavaScript code like below. This example assumes you have added the file to the "js" subfolder.

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/js/geoApi.js"></script>
<script type="text/javascript">
   // Your code goes here
</script>

Authorize

In your main code, set you Credentials for the geoApi object and call the authorize method with you success and fail callBacks functions.

<script type="text/javascript">
   $(document).ready(function () {
      GeoTrackApi.setCredentials('your username', 'your password', 'your database name');
      GeoTrackApi.authorize(ajaxCallSucceed, ajaxCallFailed);
   });
</script>

Once successfully authorized, the API will store the token in the API Object for use in future calls.

Note: The Authorization token expires after 30 minutes.

Making a call

The following example demonstrates how to use the geoApi object to request a list of Assets for a specific Client.

<script type="text/javascript">
   var params = "id=1"; //format used for GET method
   var params = "{ Id: 1 }"; //format used for POST method
   var method = "GET"; //or POST if available
   var callType = "ClientsAssets";

   GeoTrackApi.callJson(method, callType, params, ajaxCallSucceed, ajaxCallFailed);
</script>

The call explained

Argument

Description

method

The API method you are calling. Example, “GET” or “POST”.

callType

The API object you are calling. For example, “Fleets” or “ClientAssets”. See the API reference for the full set of methods.

params

The parameter object that the API method expects. For example:
{ Id: 1 }.
Passing an empty parameter will return all items for the given entity.

callbackSuccess

A function that will be called back when the API call succeeds. The callback function has a single argument called result that will contain any results returned by the API call.

callbackError

A function that will be called back if the API call failed. The callback function has a single argument that will contain error information.