Updating restaraunt struct
This commit is contained in:
parent
495e33b298
commit
1b745426df
10
scrape.go
10
scrape.go
@ -75,7 +75,17 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
sq, err := newStationQuery("data/stations.json")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
restaurants, err := scrapeUrls("data/urls.txt", wc, gc)
|
||||
for i, _ := range restaurants {
|
||||
r := &restaurants[i]
|
||||
r.closestStnName, r.closestStnDist = sq.closestStation(r.latitude, r.longitude)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
log.Print(len(restaurants))
|
||||
} else {
|
||||
|
@ -39,6 +39,9 @@ type restaurant struct {
|
||||
|
||||
latitude float64
|
||||
longitude float64
|
||||
|
||||
closestStnName string
|
||||
closestStnDist float64
|
||||
}
|
||||
|
||||
type scraper interface {
|
||||
|
17
stations.go
17
stations.go
@ -24,7 +24,10 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"os"
|
||||
|
||||
"github.com/kellydunn/golang-geo"
|
||||
)
|
||||
|
||||
type station struct {
|
||||
@ -53,6 +56,18 @@ func newStationQuery(filename string) (*stationQuery, error) {
|
||||
}
|
||||
|
||||
func (s *stationQuery) closestStation(latitude, longitude float64) (name string, distance float64) {
|
||||
queryPt := geo.NewPoint(latitude, longitude)
|
||||
|
||||
return "", 0
|
||||
var closestStn string
|
||||
minDist := math.MaxFloat64
|
||||
|
||||
for name, station := range s.stations {
|
||||
stnPt := geo.NewPoint(station.Latitude, station.Longitude)
|
||||
if currDist := queryPt.GreatCircleDistance(stnPt); currDist < minDist {
|
||||
closestStn = name
|
||||
minDist = currDist
|
||||
}
|
||||
}
|
||||
|
||||
return closestStn, minDist
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user