-
Notifications
You must be signed in to change notification settings - Fork 2
Territories Service
Territories service let's you manage Territories and Avoidance Zones on your route4me account.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
}
Territory shapes are specified here
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
zone := &territories.AvoidanceZone{
Name: "Some zone",
Color: "beeeee", //hexadecimal color
Territory: territories.TerritoryShape{
Type: territories.Circle, //Type of an area
Data: []string{"37.569752822786455,-77.47833251953125", "5000"},
},
}
newZone, err := service.AddAvoidanceZone(zone)
if err != nil {
//handle errors
return
}
}
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
zone := &territories.AvoidanceZone{
Name: "Some zone",
Color: "beeeee", //hexadecimal color
Territory: territories.TerritoryShape{
Type: territories.Polygonal, //Type of an area
Data: []string{"37.769752822786455,-77.67833251953125",
"37.75886716305343,-77.68974800109863",
"37.74763966054455,-77.6917221069336",
"37.74655084306813,-77.68863220214844",
"37.7502255383101,-77.68125076293945",
"37.74797991274437,-77.67498512268066",
"37.73327960206065,-77.6411678314209",
"37.74430510679532,-77.63172645568848",
"37.76641925847049,-77.66846199035645"},
},
}
newZone, err := service.AddAvoidanceZone(zone)
if err != nil {
//handle errors
return
}
}
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
zone := &territories.AvoidanceZone{
Name: "Some zone",
Color: "beeeee", //hexadecimal color
Territory: territories.TerritoryShape{
Type: territories.Rectangular, //Type of an area
Data: []string{"43.51668853502909,-109.3798828125","46.98025235521883,-101.865234375"},
},
}
newZone, err := service.AddAvoidanceZone(zone)
if err != nil {
//handle errors
return
}
}
By specifying DeviceID
member in Query
struct you can filter avoidance zone returned.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
zones, err := service.GetAvoidanceZones(&territories.Query{})
if err != nil {
//Handle error
return
}
//do something with zones, it's a []AvoidanceZone
}
To get a specific zone you have to obtain its zoneid
first.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
zone, err := service.GetAvoidanceZone(&territories.Query{ID: "zoneid"})
if err != nil {
//handle error
return
}
//do something with the zone
}
To remove a specific zone you have to obtain its zoneid
first.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
err := service.DeleteAvoidanceZone(&territories.Query{ID: "zoneid"})
if err != nil {
//handle error
return
}
}
To update a specific zone you have to obtain its zoneid
first.
Update overrides the previous entry based on the aforementioned zoneid
.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
zone := //get zone using Get, GetAll or constructing yourself.
contact, err := service.UpdateAvoidanceZone(zone)
if err != nil {
t.Error(err)
return
}
}
Territory shapes are specified here
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
territory := &territories.Territory{
Name: "Some territory",
Color: "beeeee", //hexadecimal color
Territory: territories.TerritoryShape{
Type: territories.Circle, //Type of an area
Data: []string{"37.569752822786455,-77.47833251953125", "5000"},
},
}
newTerritory, err := service.AddTerritory(zone)
if err != nil {
//handle errors
return
}
}
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
territory := &territories.Territory{
Name: "Some territory",
Color: "beeeee", //hexadecimal color
Territory: territories.TerritoryShape{
Type: territories.Polygonal, //Type of an area
Data: []string{"37.769752822786455,-77.67833251953125",
"37.75886716305343,-77.68974800109863",
"37.74763966054455,-77.6917221069336",
"37.74655084306813,-77.68863220214844",
"37.7502255383101,-77.68125076293945",
"37.74797991274437,-77.67498512268066",
"37.73327960206065,-77.6411678314209",
"37.74430510679532,-77.63172645568848",
"37.76641925847049,-77.66846199035645"},
},
}
newTerritory, err := service.AddTerritory(territory)
if err != nil {
//handle errors
return
}
}
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
territory := &territories.Territory{
Name: "Some zone",
Color: "beeeee", //hexadecimal color
Territory: territories.TerritoryShape{
Type: territories.Rectangular, //Type of an area
Data: []string{"43.51668853502909,-109.3798828125","46.98025235521883,-101.865234375"},
},
}
newTerritory, err := service.AddTerritory(territory)
if err != nil {
//handle errors
return
}
}
By specifying DeviceID
member in Query
struct you can filter territories returned.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
territories, err := service.GetTerritories(&territories.Query{})
if err != nil {
//Handle error
return
}
//do something with territories, it's a []Territory
}
To get a specific territory you have to obtain its territory id
first.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
territory, err := service.GetTerritory(&territories.Query{ID: "territory id"})
if err != nil {
//handle error
return
}
//do something with the territory
}
To remove a specific territory you have to obtain its territory id
first.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
err := service.DeleteTerritory(&territories.Query{ID: "territory id"})
if err != nil {
//handle error
return
}
}
To update a specific territory you have to obtain its territory id
first.
Update overrides the previous entry based on the aforementioned territory id
.
import (
"github.com/route4me/route4me-go-sdk"
"github.com/route4me/route4me-go-sdk/territories"
)
func main() {
client := route4me.NewClient("your-api-key")
service := &territories.Service{Client: client}
territory := //get zone using Get, GetAll or constructing yourself.
contact, err := service.UpdateTerritory(territory)
if err != nil {
t.Error(err)
return
}
}
You can look at service's test file for more implementation details.
- Activity
- Addressbook
- Routing
- Single Driver Route 10 Stops
- Single Driver Round Trip
- Single Depot Multiple Driver No Time Windows
- Single Depot Multiple Driver Time Windows
- Multiple Depot Multiple Driver
- Multiple Depot Multiple Driver With Time Windows
- Multiple Depot Multiple Driver With Time Windows (24 Stops)
- Tracking
- Geocoding
- Users
- Territories
- Orders
- Vehicles
- Telematics