From eb6523b330c47fc792dbaa80b3c36a441cea90ec Mon Sep 17 00:00:00 2001 From: flopp Date: Sun, 14 Feb 2016 16:12:24 +0100 Subject: [PATCH] using go-coordsparser. fixes #9 --- cmd/create-static-map/create-static-map.go | 7 +++-- staticmaps/latlng.go | 35 ---------------------- staticmaps/marker.go | 5 ++-- staticmaps/path.go | 5 ++-- 4 files changed, 11 insertions(+), 41 deletions(-) delete mode 100644 staticmaps/latlng.go diff --git a/cmd/create-static-map/create-static-map.go b/cmd/create-static-map/create-static-map.go index 25bdb1c..8efc39a 100644 --- a/cmd/create-static-map/create-static-map.go +++ b/cmd/create-static-map/create-static-map.go @@ -12,7 +12,9 @@ import ( "os" "github.com/flopp/go-staticmaps/staticmaps" + "github.com/flopp/go-coordsparser" "github.com/jessevdk/go-flags" + "github.com/golang/geo/s2" ) func main() { @@ -61,9 +63,10 @@ func main() { } if parser.FindOptionByLongName("center").IsSet() { - center, err := staticmaps.ParseLatLngFromString(opts.Center) + lat, lng, err := coordsparser.Parse(opts.Center) + fmt.Println(opts.Center, lat, lng) if err == nil { - m.SetCenter(center) + m.SetCenter(s2.LatLngFromDegrees(lat, lng)) } else { log.Fatal(err) } diff --git a/staticmaps/latlng.go b/staticmaps/latlng.go deleted file mode 100644 index 5e4f109..0000000 --- a/staticmaps/latlng.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2016 Florian Pigorsch. All rights reserved. -// -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package staticmaps - -import ( - "fmt" - "regexp" - "strconv" - - "github.com/golang/geo/s2" -) - -func ParseLatLngFromString(s string) (s2.LatLng, error) { - re := regexp.MustCompile(`^\s*([+-]?\d+\.?\d*)\s*,\s*([+-]?\d+\.?\d*)\s*$`) - - matches := re.FindStringSubmatch(s) - if matches == nil { - return s2.LatLng{}, fmt.Errorf("Cannot parse lat,lng string: %s", s) - } - - lat, err := strconv.ParseFloat(matches[1], 64) - if err != nil { - return s2.LatLng{}, fmt.Errorf("Cannot parse lat,lng string: %s", s) - } - - lng, err := strconv.ParseFloat(matches[2], 64) - if err != nil { - return s2.LatLng{}, fmt.Errorf("Cannot parse lat,lng string: %s", s) - } - - return s2.LatLngFromDegrees(lat, lng), nil -} diff --git a/staticmaps/marker.go b/staticmaps/marker.go index 327460f..45c9075 100644 --- a/staticmaps/marker.go +++ b/staticmaps/marker.go @@ -10,6 +10,7 @@ import ( "image/color" "strings" + "github.com/flopp/go-coordsparser" "github.com/golang/geo/s2" ) @@ -53,11 +54,11 @@ func ParseMarkerString(s string) ([]Marker, error) { } size = size_ } else { - ll, err := ParseLatLngFromString(ss) + lat, lng, err := coordsparser.Parse(ss) if err != nil { return nil, err } - marker := Marker{ll, color, size} + marker := Marker{s2.LatLngFromDegrees(lat, lng), color, size} markers = append(markers, marker) } diff --git a/staticmaps/path.go b/staticmaps/path.go index 78abe0e..95e68b3 100644 --- a/staticmaps/path.go +++ b/staticmaps/path.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" + "github.com/flopp/go-coordsparser" "github.com/golang/geo/s2" ) @@ -45,11 +46,11 @@ func ParsePathString(s string) (Path, error) { } path.Weight = weight } else { - ll, err := ParseLatLngFromString(ss) + lat, lng, err := coordsparser.Parse(ss) if err != nil { return Path{}, err } - path.Positions = append(path.Positions, ll) + path.Positions = append(path.Positions, s2.LatLngFromDegrees(lat, lng)) } }