private void AddMapIconAndGeofence(LocationData location)
        {
            //Add an mapicon for the given location
            MapIcon mapIcon = new MapIcon();
            mapIcon.Location = new Geopoint(location.getPosition());
            mapIcon.NormalizedAnchorPoint = new Point(0.5, 1.0);
            mapIcon.Title = location.name;
            InputMap.MapElements.Add(mapIcon);

            //Make the geofence of the given locationdata
            if(location == chosenRouteLocation)
                location.MakeNewGeofence(Int32.Parse(GeofenceRadius.Text));
            else
                location.MakeNewGeofence(location.standardGeofenceRadius);
            GeofenceMonitor.Current.Geofences.Add(location.geofence);
        }
        private void getRouteWithCurrentLocation(Geopoint startLoc, LocationData endLoc)
        {
            BasicGeoposition endLocation = endLoc.getPosition();
            Geopoint endPoint = new Geopoint(endLocation);

            GetRouteAndDirections(startLoc, endPoint, Colors.Red);
        }
        private void GetRouteButton_Click(object sender, RoutedEventArgs e)
        {
            int radius = Int32.Parse(GeofenceRadius.Text);
            if (currentLocation != null)
            {
                if (radius < 1000000)
                {
                    Summary.Text = "Making an route, please wait....";
                    Error.Text = "";
                    chosenRouteLocation = (LocationData)locationList.SelectedItem;

                    GeofenceMonitor.Current.Geofences.Clear();
                    InputMap.Routes.Clear();

                    //Remove all the mapelements except the MapIcon of the current location
                    //This will also reset the geofences, their radius will be set back to their standard geofence radius except the location for the route

                    for (int i = 0; i < InputMap.MapElements.Count; i++)
                    {
                        if (InputMap.MapElements[i] is MapIcon)
                        {
                            MapIcon icon = (MapIcon)InputMap.MapElements[i];
                            if (!icon.Title.Equals(nameCurrentLocation))
                            {
                                InputMap.MapElements.Remove(icon);
                                i--;
                            }
                        }
                        else
                        {
                            InputMap.MapElements.Remove(InputMap.MapElements[i]);
                            i--;
                        }
                    }

                    //Redraw the route locations
                    foreach (LocationData data in routeLocations)
                    {
                        AddMapIconAndGeofence(data);
                    }

                    //Get the route and draw it on the map
                    //Also redraw the geofences with their right radius
                    getRouteWithCurrentLocation(currentLocation.Point, chosenRouteLocation);
                    if ((bool)GeofenceDraw.IsChecked && chosenRouteLocation != null)
                    {
                        drawGeofence(chosenRouteLocation, radius);
                        foreach (LocationData data in routeLocations)
                        {
                            if (data != chosenRouteLocation)
                                drawGeofence(data, data.standardGeofenceRadius);
                        }
                    }
                }
                else
                {
                    Error.Text = "Radius is too big";
                }
            }
            else
            {
                Error.Text = "Current location unknown";
            }
        }
        private void drawGeofence(LocationData location, double radius)
        {
            var strokeColor = Colors.DarkBlue;
            strokeColor.A = 100;
            var fillColor = Colors.Blue;
            fillColor.A = 50;

            List<BasicGeoposition> poslist = new List<BasicGeoposition>();
            poslist.Add(location.getPosition());

            MapPolygon circlePolygon = new MapPolygon
            {
                FillColor = fillColor,
                StrokeColor = strokeColor,
                StrokeThickness = 3,
                StrokeDashed = true,
                ZIndex = 1,
                Path = new Geopath(location.GetCirclePoints(radius))
            };

            InputMap.MapElements.Add(circlePolygon);
        }