GET Location within the Real-time Aggregated Data API is the most commonly used method within the REVEAL API product suite. Integrated users use this method to retrieve regular vehicle location details throughout the day to provide context to other business systems. We recommend that the user does not pull a vehicle’s location data more frequently than every 3 to 5 minutes.
Before attempting to retrieve vehicle location information it is important to know if the REVEAL account has been updated with valid VEHICLE NUMBERS for each vehicle to be pulled via the API. The VEHICLE NUMBER and VEHICLE NAME fields are different fields within REVEAL and the VEHICLE NUMBER field is not automatically populated upon account creation.
public class Program{ public static void main(String[] args){ // Token call goes here, see TokenGenerator example // App Id from Fleetmatics Integration Manager (FIM) String appId = "companyname-p-us-4654sdf4fa351af65dsf1d"; // Vehicle Number for vehicle you wish to get the location for String vehicleNumber = "6789"; // Insert vehicle number into URI String getVehicleLocationUri = String.format("https://fim.api.ENV.fleetmatics.com/rad/v1/vehicles/%s/location", vehicleNumber); // Call method to GET vehicle location String location = new GET_Vehicle_Location().GetVehicleLocation(/* token auth string passed here */, getVehicleLocationUri, appId); // Display results System.out.println(location); } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import javax.net.ssl.HttpsURLConnection; import java.net.MalformedURLException; import java.net.URL; public class GET_Vehicle_Location { public String GetVehicleLocation(String authString, String getVehicleLocationUri, String appId) { String location = ""; try { // Construct authentication header for FIM String authHeader = String.format("Atmosphere atmosphere_app_id=%s, Bearer %s", appId, authString); URL url = new URL(_getTokenUri); // Construct a url with the earlier supplied GetToken URI HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); // Open a new Https connection for transmission conn.setRequestMethod("GET"); // Set request type to GET conn.setRequestProperty("Authorization", authHeader); // Set Authorization Header conn.setRequestProperty("Accept", "text/plain"); // Denote type of response expected conn.setDoOutput(false); // Do not send request body // Execute request, read response. If we do not receive a 200 OK, throw exception if (conn.getResponseCode() != HttpsURLConnection.HTTP_OK) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } // Reads text from a character-input stream BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); location = br.readLine(); // Read the buffer into the location variable, not including any line-termination characters conn.disconnect(); // End connection to free resources } catch (MalformedURLException e) { // Required Exception e.printStackTrace(); } catch (IOException e) { // Required Exception e.printStackTrace(); } return location; } }
To download the source code .zip for this example, click HERE.
All sample code is provided by Fleetmatics, A Verizon Company, for illustrative purposes only. These examples have not been thoroughly tested under all conditions. Fleetmatics, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs. All programs contained herein are provided to you “AS IS” without any warranties of any kind.