mirror of
https://github.com/imjasonh/staticmaps
synced 2026-07-08 10:55:03 +00:00
support StreetView Images API
This commit is contained in:
parent
65e4dccc17
commit
fbc80b3a45
3 changed files with 73 additions and 0 deletions
4
maps.go
4
maps.go
|
|
@ -85,3 +85,7 @@ func encodeLocations(ls []Location) string {
|
|||
}
|
||||
return strings.Join(s, "|")
|
||||
}
|
||||
|
||||
func Float64(f float64) *float64 {
|
||||
return &f
|
||||
}
|
||||
|
|
|
|||
14
maps_test.go
14
maps_test.go
|
|
@ -75,3 +75,17 @@ func TestStaticMap(t *testing.T) {
|
|||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreetView(t *testing.T) {
|
||||
c := NewClient("")
|
||||
s := Size{600, 300}
|
||||
opts := &StreetViewOpts{
|
||||
Location: &LatLng{46.414382, 10.013988},
|
||||
Heading: Float64(151.78),
|
||||
Pitch: -0.76,
|
||||
}
|
||||
t.Logf("%s", baseURL+streetview(s, opts))
|
||||
if _, err := c.StreetView(s, opts); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
55
streetview.go
Normal file
55
streetview.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package maps
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (c Client) StreetView(s Size, opts *StreetViewOpts) (io.ReadCloser, error) {
|
||||
resp, err := c.do(baseURL + streetview(s, opts))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, HTTPError{resp}
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
func streetview(s Size, opts *StreetViewOpts) string {
|
||||
p := url.Values{}
|
||||
p.Set("size", s.String())
|
||||
opts.update(p)
|
||||
return "streetview?" + p.Encode()
|
||||
}
|
||||
|
||||
type StreetViewOpts struct {
|
||||
Location Location
|
||||
Pano string // panoramio ID
|
||||
Heading *float64 // 0-360
|
||||
FOV *float64 // 0-120, 90 default
|
||||
Pitch float64 // -90 to +90
|
||||
}
|
||||
|
||||
func (s *StreetViewOpts) update(p url.Values) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
if s.Location != nil {
|
||||
p.Set("location", s.Location.Location())
|
||||
}
|
||||
if s.Pano != "" {
|
||||
p.Set("pano", s.Pano)
|
||||
}
|
||||
if s.Heading != nil {
|
||||
p.Set("heading", fmt.Sprintf("%f", *s.Heading))
|
||||
}
|
||||
if s.FOV != nil {
|
||||
p.Set("fov", fmt.Sprintf("%f", *s.FOV))
|
||||
}
|
||||
if s.Pitch != 0 {
|
||||
p.Set("pitch", fmt.Sprintf("%f", s.Pitch))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue