1

Updating restaraunt struct

This commit is contained in:
Alex Yatskov 2015-08-22 17:54:46 +09:00
parent 495e33b298
commit 1b745426df
3 changed files with 29 additions and 1 deletions

View File

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

View File

@ -39,6 +39,9 @@ type restaurant struct {
latitude float64
longitude float64
closestStnName string
closestStnDist float64
}
type scraper interface {

View File

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