public State Find(string userId, double lat, double lng, int rangeId) { var state = GetState(userId); if (state.Poi != null) { Stop(userId, state, true); } // set coordinates state.Coordinates = new GeoPoint(lat, lng); // get pois from cache or from Overpass List <Poi> pois; if (state.CachedResult != null && state.CachedResult.IsEqual(state.Coordinates, rangeId)) { pois = state.CachedResult.Pois; } else { pois = QueryPois(rangeId, state); state.CachedResult = new CachedResult { Coordinates = state.Coordinates, RangeId = rangeId, Pois = pois }; } // choose poi var distance = _rangeDistances[rangeId]; var poi = ChoosePoi(state.Coordinates, distance, pois, state.User, state.LastCategoriesFound, state.LastTagsFound); if (poi == null) { state.Poi = null; state.Route = null; } else { var mapbox = new Mapbox(); var route = mapbox.Walk(state.Coordinates, poi.Coordinates); state.Poi = poi; state.Route = route; } SetIsNear(state); SaveState(state); return(state); }
public State Move(string userId, double lat, double lng) { var state = GetState(userId); var changed = state.Coordinates == null || Math.Abs(state.Coordinates.Lat - lat) > CompareTolerance || Math.Abs(state.Coordinates.Lng - lng) > CompareTolerance; state.Coordinates = new GeoPoint(lat, lng); if (state.Poi != null && changed) { var mapbox = new Mapbox(); var route = mapbox.Walk(state.Coordinates, state.Poi.Coordinates); state.Route = route; } SetIsNear(state); SaveState(state); return(state); }