예제 #1
0
        private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            //Load desired places from user selection
            var grItems = e.NavigationParameter as IEnumerable <SampleDataItem>;

            if (grItems != null)
            {
                foreach (var item in grItems)
                {
                    var pos = item.Position.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    var key = pos[0].Trim() + pos[1].Trim();

                    if (!VisitedPlaces.ContainsKey(key))
                    {
                        Place p = new Place
                        {
                            Name        = item.Title,
                            Address     = item.Description,
                            DisplayName = item.Title + Environment.NewLine + item.Description,
                            Latitude    = Convert.ToDouble(pos[0].Trim()),
                            Longitude   = Convert.ToDouble(pos[1].Trim())
                        };
                        VisitedPlaces[key] = p;
                        ProbableVisitedPlaces.Add(p);
                    }
                }
            }
            locTimer.Stop();
            locTimer.Start();
        }
예제 #2
0
        private async Task LoadDataFromRuntimeLocationTrack()
        {
            foreach (var vplace in Util.UserProfileData.ProbableVisitedPlaces)
            {
                if (!VisitedPlaces.ContainsKey(vplace.UniqueId))
                {
                    VisitedPlaces[vplace.UniqueId] = vplace;
                    (VisitedPlaces[vplace.UniqueId] as Place).DisplayName = (VisitedPlaces[vplace.UniqueId] as Place).Address;
                    ProbableVisitedPlaces.Insert(0, VisitedPlaces[vplace.UniqueId] as Place);

                    //refresh the map to show best possible route
                    await ShowBestPossibleRoutes();
                }
            }
        }
예제 #3
0
        private async Task ShowBestPossibleRoutes()
        {
            try
            {
                //Show best possible route path
                if (Util.UserProfileData.CurrentPlace != null)
                {
                    await MapViewer.InvokeScriptAsync("Reset", null);

                    List <KeyValuePair <double, string> > places = new List <KeyValuePair <double, string> >();

                    foreach (var item in ProbableVisitedPlaces)
                    {
                        places.Add(new KeyValuePair <double, string>(
                                       CalculateDistance(Util.UserProfileData.StartPlace.Latitude, Util.UserProfileData.StartPlace.Longitude, item.Latitude, item.Longitude), item.UniqueId));
                    }

                    var maxdistance         = places.Max(p => p.Key);
                    var destinationUniqueId = places.Where(p => p.Key == maxdistance).Select(p => p.Value).First();
                    var destination         = ProbableVisitedPlaces.First(p => p.UniqueId == destinationUniqueId);

                    var waypoints = ProbableVisitedPlaces.Where(p => p.UniqueId != Util.UserProfileData.StartPlace.UniqueId && p.UniqueId != destinationUniqueId);
                    foreach (var point in waypoints)
                    {
                        await MapViewer.InvokeScriptAsync("createWayPoints", new string[] { point.Latitude.ToString(), point.Longitude.ToString(), point.DisplayName });
                    }

                    await MapViewer.InvokeScriptAsync("calcRoute", new string[] { Util.UserProfileData.StartPlace.Latitude.ToString(),
                                                                                  Util.UserProfileData.StartPlace.Longitude.ToString(), destination.Latitude.ToString(), destination.Longitude.ToString(),
                                                                                  Util.UserProfileData.StartPlace.Address, destination.DisplayName });
                }
            }
            catch (Exception ex)
            {
                Util.HandleMessage("Map direction couldn't be loaded", ex.ToString(), "Error");
            }
        }