2019-10-20 03:34:17 +00:00
|
|
|
package tile38
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"github.com/go-redis/redis"
|
2019-12-15 07:50:05 +00:00
|
|
|
"github.com/supanadit/geo-smart-system/model"
|
2019-10-20 03:34:17 +00:00
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2020-01-04 00:44:42 +00:00
|
|
|
type SubObject struct {
|
2019-10-20 03:34:17 +00:00
|
|
|
Type string `json:"type"`
|
|
|
|
Coordinates []float64 `json:"coordinates"`
|
|
|
|
}
|
|
|
|
|
2020-01-04 00:44:42 +00:00
|
|
|
func (tile38SubObject SubObject) Lng() float64 {
|
2019-10-20 03:34:17 +00:00
|
|
|
return tile38SubObject.Coordinates[0]
|
|
|
|
}
|
|
|
|
|
2020-01-04 00:44:42 +00:00
|
|
|
func (tile38SubObject SubObject) Lat() float64 {
|
2019-10-20 03:34:17 +00:00
|
|
|
return tile38SubObject.Coordinates[1]
|
|
|
|
}
|
|
|
|
|
2020-01-04 00:44:42 +00:00
|
|
|
func FromLocation(location model.Location) SubObject {
|
|
|
|
var tile38SubObject SubObject
|
2019-10-20 03:34:17 +00:00
|
|
|
tile38SubObject.Type = "Point"
|
|
|
|
lng, _ := strconv.ParseFloat(location.Lng, 64)
|
|
|
|
lat, _ := strconv.ParseFloat(location.Lat, 64)
|
|
|
|
tile38SubObject.Coordinates = []float64{
|
|
|
|
lng,
|
|
|
|
lat,
|
|
|
|
}
|
|
|
|
return tile38SubObject
|
|
|
|
}
|
|
|
|
|
2020-01-04 00:44:42 +00:00
|
|
|
func GetDataLocation(client *redis.Client, typeLocation string, id string) (Object, error) {
|
|
|
|
var tile38Object Object
|
2019-10-20 03:34:17 +00:00
|
|
|
var err error
|
|
|
|
data, err := client.Do("GET", typeLocation, id).Result()
|
|
|
|
if err == nil {
|
|
|
|
dataMarshal, err := json.Marshal(data)
|
|
|
|
if err == nil {
|
|
|
|
fmt.Println(string(dataMarshal))
|
|
|
|
err = json.Unmarshal(dataMarshal, &tile38Object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tile38Object, err
|
|
|
|
}
|