mirror of
https://github.com/flopp/go-staticmaps.git
synced 2025-12-08 18:26:36 +00:00
using go-coordsparser. fixes #9
This commit is contained in:
parent
bd160138b9
commit
eb6523b330
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user