Пример #1
0
func (pl *Player) RPC_PQuery() ([]interface{}, error) {
	const tileDist = 1.5

	tx, ty := geom.LL2TilePos(float64(pl.Lat), float64(pl.Lon))
	maxLat, maxLon := geom.TilePos2LL(tx+tileDist, ty-tileDist)
	minLat, minLon := geom.TilePos2LL(tx-tileDist, ty+tileDist)

	//log.Println("q pos:", minLon, maxLon, minLat, maxLat)
	//log.Println("q que:", qtPlayers.Query(minLon, maxLon, minLat, maxLat))

	vals := qtPlayers.Query(minLon, maxLon, minLat, maxLat)
	ret := make([]interface{}, 0, len(vals))
	for i := 0; i < len(vals); i++ {
		op := vals[i]
		//ignore self
		if op.V == pl.PId {
			continue
		}
		rop := make([]interface{}, 3)
		rop[0] = op.Y
		rop[1] = op.X
		rop[2] = op.V
		ret = append(ret, rop)
	}

	return ret, nil
}
Пример #2
0
func GetPOIs(lat float64, lon float64) (pois []*POI, pending int) {
	x, y := geom.LL2TilePos(lat, lon)
	xInt, yInt := int(x), int(y)

	pois = make([]*POI, 0)

	for iX := xInt - 1; iX <= xInt+1; iX++ {
		for iY := yInt - 1; iY <= yInt+1; iY++ {
			mt := GetMapTile(strconv.Itoa(iX) + "," + strconv.Itoa(iY))
			if mt != nil {
				//pois = append(pois, mt.Pois...)
				for _, poi := range mt.Pois {
					poi.UpdateInfo()
					if poi.IsValid() {
						pois = append(pois, poi)
					}
				}
			} else {
				pending++
			}
		}
	}

	for i := 0; i < len(pois); i++ {
		for j := i + 1; j < len(pois); j++ {
			pi := pois[i]
			po := pois[j]
			dist := geom.LLDistanceKm(pi.Lat, pi.Lon, po.Lat, po.Lon)
			if dist < 0.025 {
				//log.Println("skippoi", po.Name, dist)
				pois[j], pois = pois[len(pois)-1], pois[:len(pois)-1]
				j--
			}
		}
	}

	return
}
Пример #3
0
func LL2MapPos(lat float64, lon float64) string {
	x, y := geom.LL2TilePos(lat, lon)
	xInt, yInt := int(x), int(y)
	return strconv.Itoa(xInt) + "," + strconv.Itoa(yInt)
}