Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Android Button Command very slow


Maybe someone can help me.

When I fire a command over a button in Xamarin.forms, Android is very, very slow, takes 30 minutes and longer to add 10000 Polylines. If I ran the same command without the button click, it add all the 10000 polyline in 3 seconds.

What I try to do, is read a bigger XML file and add the map polylines.

public Command LoadingGPX { get; }

public TrackViewModel()
    // VERY SLOW:
            LoadingGPX = new Command(() => LoadGPXTrack());


    public async void LoadGPXTrack()

        string newFile = "testgpx99.gpx";
        XDocument gpxDoc = await LoadGpxDocLoad(newFile);
        XNamespace gpx = GetGpxNameSpace();
        if (gpxDoc != null)
        var tracks = from track in gpxDoc.Descendants(gpx + "trk")
                     select new
                         Name = track.Element(gpx + "name") != null ?
                        track.Element(gpx + "name").Value : null,
                         Segs = (
                            from trackpoint in track.Descendants(gpx + "trkpt")
                            select new
                                Latitude = trackpoint.Attribute("lat").Value,
                                Longitude = trackpoint.Attribute("lon").Value,
                                Elevation = trackpoint.Element(gpx + "ele") != null ?
                                trackpoint.Element(gpx + "ele").Value : null,
                                Time = trackpoint.Element(gpx + "time") != null ?
                                trackpoint.Element(gpx + "time").Value : null

        StringBuilder sb = new StringBuilder();

        int count = 0;
        double prevLatitude = 0;
        double prevLongitude = 0;
        double distanceTotal = 0;
        double distance = 0;
        foreach (var trk in tracks)
            foreach (var trkSeg in trk.Segs)
                var polyline = new Polyline();

                string NumberDecimalSeparator = System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator;

                double invariantCultureLatitude = 0;
                double invariantCultureLongitude = 0;
                double invariantCultureElevation = 0;

                if (trkSeg.Latitude.Contains(".") && NumberDecimalSeparator == ",")
                    double.TryParse(trkSeg.Latitude, NumberStyles.Any, CultureInfo.InvariantCulture, out invariantCultureLatitude);
                    double.TryParse(trkSeg.Longitude, NumberStyles.Any, CultureInfo.InvariantCulture, out invariantCultureLongitude);
                    double.TryParse(trkSeg.Elevation, NumberStyles.Any, CultureInfo.InvariantCulture, out invariantCultureElevation);
                    double.TryParse(trkSeg.Latitude, NumberStyles.Any, CultureInfo.CurrentCulture, out invariantCultureLatitude);
                    double.TryParse(trkSeg.Longitude, NumberStyles.Any, CultureInfo.CurrentCulture, out invariantCultureLongitude);
                    double.TryParse(trkSeg.Elevation, NumberStyles.Any, CultureInfo.CurrentCulture, out invariantCultureElevation);

                if (count > 0)
                    Location sourceCoordinates = new Location(prevLatitude, prevLongitude);
                    Location destinationCoordinates = new Location(invariantCultureLatitude, invariantCultureLongitude);
                    distance = Location.CalculateDistance(sourceCoordinates, destinationCoordinates, DistanceUnits.Kilometers);

                distanceTotal += distance;
                prevLatitude = invariantCultureLatitude;
                prevLongitude = invariantCultureLongitude;

                    //Custom Map very slow over Android
                    MyPolyline.Geopath.Add(new Position(invariantCultureLatitude, invariantCultureLongitude));
                    MyPolyline.StrokeColor = Xamarin.Forms.Color.GreenYellow;
                    MyPolyline.StrokeWidth = 3f;

                    _gpxTrack.Add(new GPXTrack()
                    Latitude = invariantCultureLatitude,
                    Longitude = invariantCultureLongitude,
                    Elevation = invariantCultureElevation,
                    Distance = distanceTotal

Thanks for any help,




  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Please try to update your xamarin forms nuget packages to the latest. Then re-test it. if this issue is still existed. I met the same issue in the xamarin forms 4.5, when update it to xamarin forms 4.7, this issue is disappear.

  • anteroantero Member ✭✭

    @LeonLu said:
    Please try to update your xamarin forms nuget packages to the latest. Then re-test it. if this issue is still existed. I met the same issue in the xamarin forms 4.5, when update it to xamarin forms 4.7, this issue is disappear.

    Hi LeonLu,

    thank you for the answer, I have already the newst Version of xamarin.forms installed



  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Could you share completely code about TrackViewModel that I can reproduce this issue?

  • anteroantero Member ✭✭
  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Please see the JohnHardman's reply in above link.

Sign In or Register to comment.