image of to-from map
This commit is contained in:
44
main.go
44
main.go
@@ -9,6 +9,7 @@ import (
|
||||
"local/truckstop/config"
|
||||
"local/truckstop/message"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"sort"
|
||||
@@ -337,8 +338,48 @@ func sendJob(job broker.Job) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
maps := config.Get().Maps
|
||||
pickup := fmt.Sprintf("%s,%s", url.QueryEscape(job.Pickup.City), job.Pickup.State)
|
||||
dropoff := fmt.Sprintf("%s,%s", url.QueryEscape(job.Dropoff.City), job.Dropoff.State)
|
||||
if maps.Pathed {
|
||||
directionsURI := fmt.Sprintf(maps.DirectionsURIFormat, pickup, dropoff)
|
||||
resp, err := http.Get(directionsURI)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return true, fmt.Errorf("bad status getting path: %d", resp.StatusCode)
|
||||
}
|
||||
var directionsResp struct {
|
||||
Routes []struct {
|
||||
Legs []struct {
|
||||
Steps []struct {
|
||||
StartLocation struct {
|
||||
Lat float32 `json:"lat"`
|
||||
Lng float32 `json:"lng"`
|
||||
} `json:"start_location"`
|
||||
} `json:"steps"`
|
||||
} `json:"legs"`
|
||||
} `json:"routes"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&directionsResp); err != nil {
|
||||
return true, err
|
||||
}
|
||||
if len(directionsResp.Routes) < 1 || len(directionsResp.Routes[0].Legs) < 1 || len(directionsResp.Routes[0].Legs[0].Steps) < 1 {
|
||||
} else {
|
||||
latLngPath := make([]string, 0)
|
||||
for _, v := range directionsResp.Routes[0].Legs[0].Steps {
|
||||
latLngPath = append(latLngPath, fmt.Sprintf("%.9f,%.9f", v.StartLocation.Lat, v.StartLocation.Lng))
|
||||
}
|
||||
pathQuery := strings.Join(latLngPath, "|")
|
||||
uri := fmt.Sprintf(maps.PathedURIFormat, pathQuery, pickup, dropoff)
|
||||
log.Printf("sending pathed image: %s", uri)
|
||||
if err := sender.SendImage(uri); err != nil {
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if maps.Pickup {
|
||||
pickup := fmt.Sprintf("%s,%s", url.QueryEscape(job.Pickup.City), job.Pickup.State)
|
||||
uri := fmt.Sprintf(maps.URIFormat, pickup, pickup)
|
||||
log.Printf("sending pickup image: %s", uri)
|
||||
if err := sender.SendImage(uri); err != nil {
|
||||
@@ -346,7 +387,6 @@ func sendJob(job broker.Job) (bool, error) {
|
||||
}
|
||||
}
|
||||
if maps.Dropoff {
|
||||
dropoff := fmt.Sprintf("%s,%s", url.QueryEscape(job.Dropoff.City), job.Dropoff.State)
|
||||
uri := fmt.Sprintf(maps.URIFormat, dropoff, dropoff)
|
||||
log.Printf("sending dropoff image: %s", uri)
|
||||
if err := sender.SendImage(uri); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user