Location API
With Smartcar, tracking a car’s location is as easy as a single API request.
Retrieve a vehicle’s last known location by geographic coordinates.
const smartcar = require('smartcar');
// Get all vehicles associated with this access token
const {vehicles} = await smartcar.getVehicleIds("<access-token>");
// Construct a new vehicle instance using the first vehicle's id
const vehicle = new smartcar.Vehicle(vehicles[0], "<access-token>");
// Fetch the vehicle's location
const location = await vehicle.location();
console.log(location);
import smartcar
# Get all vehicles associated with this access token
response = smartcar.get_vehicle_ids("<access-token>")
# Construct a new vehicle instance using the first vehicle's id
vehicle = smartcar.Vehicle(response["vehicles"][0], "<access-token>")
# Fetch the vehicle's location
location = vehicle.location()
print(location)
import com.smartcar.sdk.*;
// Get all vehicles associated with this access token
SmartcarResponse<VehicleIds> response = AuthClient.getVehicleIds("<access-token>");
String[] vehicleIds = response.getData().getVehicleIds();
// Construct a new vehicle instance using the first vehicle's id
Vehicle vehicle = new Vehicle(vehicleIds[0], "<access-token>");
// Fetch the vehicle's location
SmartcarResponse<VehicleLocation> location = vehicle.location();
System.out.println(location.getData().getLatitude() + ", " + location.getData().getLongitude());
import (
"context"
smartcar "github.com/smartcar/go-sdk"
);
// Create a smartcar client
var smartcarClient = smartcar.NewClient();
// Get all vehicles associated with this access token
var vehicleIDs, resErr = smartcarClient.GetVehicleIDs(
context.TODO(),
&smartcar.VehicleIDsParams{Access: "<access-token>"},
);
// Construct a new vehicle instance using the first vehicle's id
var vehicle = smartcarClient.NewVehicle(&smartcar.VehicleParams{
ID: vehicleIDs.VehicleIDs[0],
AccessToken: "<access-token>"},
);
// Fetch the vehicle's location
var fuel, resErr = vehicle.GetLocation(context.TODO());
require 'smartcar'
# Get all vehicles associated with this access token
vehicle_ids = Smartcar::Vehicle.all_vehicle_ids(token: token)
# Construct a new vehicle instance using the first vehicle's id
vehicle = Smartcar::Vehicle.new(
token: "<access-token>",
id: vehicle_ids.first
)
# Fetch the vehicle's location
location = vehicle.location()
puts location.to_hash.slice(*%I(latitude, longitude))
// Example response from Smartcar
{
"latitude": 37.4292,
"longitude": 122.1381
}
Build simple, affordable fleet tracking software for businesses of all sizes.
Learn more about fleet managementDisplay nearby EV charging stations and let your customers plan trips directly in your app.
Learn more about EV charging