Ejemplo n.º 1
0
        public async Task <int> findNearestSite()
        {
            try
            {
                geoLoc = new Geolocator {
                    ReportInterval = 2000
                };
                var pos = await geoLoc.GetGeopositionAsync();

                var p      = pos.Coordinate.Point;
                var gpsPos = new GpsPoint {
                    twd97Lat = p.Position.Latitude, twd97Lon = p.Position.Longitude
                };

                var dists = new List <double>();
                foreach (var s in sitesGeoDict)
                {
                    dists.Add(StaticTaqModel.posDist(gpsPos, s.Value));
                }
                var minId = dists.FindIndex(v => v == dists.Min());
                nearestSite = sitesGeoDict.Keys.ToList()[minId];
            }
            catch
            {
                throw new Exception(resLoader.GetString("positioningNearestSiteFail"));
            }
            return(0);
        }
Ejemplo n.º 2
0
 // Squared Euclidean distance.
 public static double posDist(GpsPoint p1, GpsPoint p2)
 {
     return(Math.Pow(p1.twd97Lat - p2.twd97Lat, 2) + Math.Pow(p1.twd97Lon - p2.twd97Lon, 2));
 }