本文整理汇总了Golang中github.com/skypies/geo.Latlong.Dist方法的典型用法代码示例。如果您正苦于以下问题:Golang Latlong.Dist方法的具体用法?Golang Latlong.Dist怎么用?Golang Latlong.Dist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skypies/geo.Latlong
的用法示例。
在下文中一共展示了Latlong.Dist方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FixupComplaint
func FixupComplaint(c *types.Complaint, key *datastore.Key) {
// 0. Snag the key, so we can refer to this object later
c.DatastoreKey = key.Encode()
// 1. GAE datastore helpfully converts timezones to UTC upon storage; fix that
c.Timestamp = date.InPdt(c.Timestamp)
// 2. Compute the flight details URL, if within 24 days
age := date.NowInPdt().Sub(c.Timestamp)
if age < time.Hour*24 {
// c.AircraftOverhead.Fr24Url = c.AircraftOverhead.PlaybackUrl()
c.AircraftOverhead.Fr24Url = "http://flightaware.com/live/flight/" +
c.AircraftOverhead.FlightNumber
// Or: http://flightaware.com/live/flight/UAL337/history/20151215/ [0655Z/KLAX/KSFO]
// date is UTC of departure time; might be tricky to guess :/
}
// 3. Compute distances, if we have an aircraft
if c.AircraftOverhead.FlightNumber != "" {
a := c.AircraftOverhead
aircraftPos := geo.Latlong{a.Lat, a.Long}
observerPos := geo.Latlong{c.Profile.Lat, c.Profile.Long}
c.Dist2KM = observerPos.Dist(aircraftPos)
c.Dist3KM = observerPos.Dist3(aircraftPos, a.Altitude)
}
}
示例2: FindOverhead
func (fr *Fr24) FindOverhead(observerPos geo.Latlong, overhead *Aircraft, grabAnything bool) (debug string, err error) {
debug = fmt.Sprintf("*** FindOverhead for %s, at %s\n", observerPos,
date.NowInPdt())
// Create a bounding box that's ~40m square, centred on the input lat,long
// This is a grievous fudge http://www.movable-type.co.uk/scripts/latlong.html
lat_20miles := 0.3
long_20miles := 0.35
nearby := []Aircraft{}
if err = fr.ListBbox(observerPos.Lat-lat_20miles, observerPos.Long-long_20miles,
observerPos.Lat+lat_20miles, observerPos.Long+long_20miles, &nearby); err != nil {
debug += fmt.Sprintf("Lookup error: %s\n", err)
return
}
for i, a := range nearby {
aircraftPos := geo.Latlong{a.Lat, a.Long}
nearby[i].Dist = observerPos.Dist(aircraftPos)
nearby[i].Dist3 = observerPos.Dist3(aircraftPos, a.Altitude)
nearby[i].BearingFromObserver = observerPos.BearingTowards(aircraftPos)
}
sort.Sort(byDist3(nearby))
debug += "** nearby list:-\n" + DebugFlightList(nearby)
filtered := filterAircraft(nearby)
if len(filtered) == 0 {
debug += "** all empty after filtering\n"
return
}
debug += "** filtered:-\n" + DebugFlightList(filtered)
if grabAnything {
*overhead = filtered[0]
debug += "** grabbed 1st\n"
} else {
// closest plane has to be within 12 km to be 'overhead', and it has
// to be 4km away from the next-closest
if filtered[0].Dist3 < 12.0 {
if (len(filtered) == 1) || (filtered[1].Dist3-filtered[0].Dist3) > 4.0 {
*overhead = filtered[0]
debug += "** selected 1st\n"
} else {
debug += "** 2nd was too close to 1st\n"
}
} else {
debug += "** 1st was too far away\n"
}
}
return
}
示例3: SnapshotAt
func (f Flight) SnapshotAt(t time.Time, pos *geo.Latlong) (*FlightSnapshot, error) {
if len(f.Track) == 0 {
return nil, fmt.Errorf("SnapshotAt: found no trackpoints")
}
t = t.UTC()
start, end := f.Track[0].TimestampUTC, f.Track[len(f.Track)-1].TimestampUTC
if t.Before(start) {
return nil, fmt.Errorf("SnapshotAt: t<start (t=%s, start=%s)", t, start)
} else if t.After(end) {
return nil, fmt.Errorf("SnapshotAt: t>end (t=%s, end=%s)", t, end)
}
for i, tp := range f.Track {
if i == len(f.Track)-1 {
break
}
if tp.TimestampUTC.Before(t) && f.Track[i+1].TimestampUTC.After(t) {
// Grab the two trackpoints that bracket our time
snap := &FlightSnapshot{
F: f,
Pos: f.Track[i],
NextPos: f.Track[i+1],
}
if pos != nil {
snap.Reference = *pos
snap.DistToReferenceKM = pos.Dist(f.Track[i].Latlong)
snap.BearingToReference = float64(int64(pos.BearingTowards(f.Track[i].Latlong)))
}
return snap, nil
}
}
return nil, fmt.Errorf("SnapshotAt: fell off the end, bad track ?")
}
示例4: FindAllOverhead
func (fr *Fr24) FindAllOverhead(observerPos geo.Latlong, overhead *flightid.Aircraft, grabAnything bool) (outAll []*Aircraft, outFilt []*Aircraft, debug string, err error) {
outAll = []*Aircraft{}
outFilt = []*Aircraft{}
debug = fmt.Sprintf("*** FindOverhead for %s, at %s\n", observerPos, date.NowInPdt())
debug += fmt.Sprintf("* url: http://%s%s?array=1&bounds=%s\n", fr.host, kListUrlPath, "...")
// Create a bounding box that's ~40m square, centred on the input lat,long
// This is a grievous fudge http://www.movable-type.co.uk/scripts/latlong.html
lat_20miles := 0.3
long_20miles := 0.35
nearby := []Aircraft{}
if err = fr.ListBbox(observerPos.Lat-lat_20miles, observerPos.Long-long_20miles,
observerPos.Lat+lat_20miles, observerPos.Long+long_20miles, &nearby); err != nil {
debug += fmt.Sprintf("Lookup error: %s\n", err)
return
}
for i, a := range nearby {
// Hack for Surf Air; promote callsigns into (invalid_ flightnumbers, so they don't get stripped
if a.FlightNumber == "" && regexp.MustCompile("^URF\\d+$").MatchString(a.Callsign) {
nearby[i].FlightNumber = a.Callsign
} else if a.FlightNumber != "" {
if _, _, err := fdb.ParseIata(a.FlightNumber); err != nil {
debug += "** saw bad flightnumber '" + a.FlightNumber + "' from fr24\n"
nearby[i].FlightNumber = ""
}
}
aircraftPos := geo.Latlong{a.Lat, a.Long}
nearby[i].Dist = observerPos.Dist(aircraftPos)
nearby[i].Dist3 = observerPos.Dist3(aircraftPos, a.Altitude)
nearby[i].BearingFromObserver = observerPos.BearingTowards(aircraftPos)
}
sort.Sort(byDist3(nearby))
debug += "** nearby list:-\n" + DebugFlightList(nearby)
filtered := filterAircraft(nearby)
if len(filtered) == 0 {
debug += "** all empty after filtering\n"
return
}
for i, _ := range nearby {
outAll = append(outAll, &nearby[i])
}
for i, _ := range filtered {
outFilt = append(outFilt, &filtered[i])
}
debug += "** filtered:-\n" + DebugFlightList(filtered)
if grabAnything {
filtered[0].IntoFlightIdAircraft(overhead)
debug += "** grabbed 1st\n"
} else {
// closest plane has to be within 12 km to be 'overhead', and it has
// to be 4km away from the next-closest
if filtered[0].Dist3 < 12.0 {
if (len(filtered) == 1) || (filtered[1].Dist3-filtered[0].Dist3) > 4.0 {
filtered[0].IntoFlightIdAircraft(overhead)
debug += "** selected 1st\n"
} else {
debug += "** 2nd was too close to 1st\n"
}
} else {
debug += "** 1st was too far away\n"
}
}
return
}