using go-coordsparser. fixes #9

This commit is contained in:
flopp 2016-02-14 16:12:24 +01:00
parent bd160138b9
commit eb6523b330
4 changed files with 11 additions and 41 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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))
}
}