Skip to content
Maciej Mionskowski edited this page Mar 6, 2017 · 5 revisions

Tracking service let's you set the current GPS position for a specific device and route.

Creating Service

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/tracking"
	"github.com/route4me/route4me-go-sdk/routing" //You might need routing for device type
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &tracking.Service{Client: client}
}

Endpoints

Setting GPS position

To set the GPS position you have to obtain route-id first. Learn how to do that.

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/tracking"
	"github.com/route4me/route4me-go-sdk/routing" //You might need routing for device type
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &tracking.Service{Client: client}
	query := &tracking.GPS{
		RouteID:         "route-id",
		Latitude:        33.14384,
		Longitude:       -83.22466,
		Course:          1,
		Speed:           120,
		DeviceType:      routing.IPad,
		MemberID:        1,
		DeviceGUID:      "TEST_GPS",
		DeviceTimestamp: "2014-06-14 17:43:35",
	}
	_, err = service.SetGPS(query)
	if err != nil {
		//handle errors
		return
	}
}

Getting last location

In order to get last location, you have to acquire route-id. Learn how to do that.

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/tracking"
	"github.com/route4me/route4me-go-sdk/routing" //You might need routing for device type
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &tracking.Service{Client: client}
	dataObject, err := service.GetLastLocation("route-id")
	if err != nil {
		//handle errors
	}
	//dataObject.TrackingHistory contains all tracking history
}

Getting device location history from time range

In order to device's location history, you have to acquire route-id. Learn how to do that.

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/tracking"
	"github.com/route4me/route4me-go-sdk/routing" //You might need routing for device type
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &tracking.Service{Client: client}
	trackingHistory, err := service.GetDeviceLocationHistory(&tracking.TrackingHistoryQuery{
		TimePeriod: tracking.TimePeriodCustom,
		StartDate:  unix-time-start-date,
		EndDate:    unix-time-end-date,
		RouteID:    `route-id`,
	})
	if err != nil {
		//handle errors
	}
	//trackingHistory contains all tracking history
}

Getting routee tracking data / asset tracking

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/tracking"
	"github.com/route4me/route4me-go-sdk/routing" //You might need routing for device type
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &tracking.Service{Client: client}
	assetTracking, err := service.TrackAssets(`tracking-code`)
	if err != nil {
		//handle errors
	}
	//assetTracking contains all tracking data
}

You can look at service's test file for more implementation details.