Extracting data from CSV file (fusion table and kml workaround)

前端 未结 3 1123
难免孤独
难免孤独 2021-01-17 23:04

In Xamarin google maps for Android using C# you can create polygons like so based on this tutorial:

    public void OnMapReady(GoogleMap googleMap)
    {
            


        
3条回答
  •  Happy的楠姐
    2021-01-17 23:19

    I'm not sure to understand your questions but I think that can help:

    You have to read the csv file line by line and foreach line extract the third argument, remove the quote and read the result with a XMLReader for extract the line you want (coordinate). After you split the result on white space, you get the list of LatLng and you split each LatLng on ",", then you've got all the information you need.

    System.IO.StreamReader file = new System.IO.StreamReader(@"file.csv");
    string line = file.ReadLine(); //escape the first line
    while((line = file.ReadLine()) != null)
    {
        var xmlString = line.Split({","})[2]; // or 3
        **Update**
        xmlString = xmlString.Replace("\"","")
    
        using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
        {
            reader.ReadToFollowing("coordinate");
            string coordinate = reader.Value;
            PolylineOptions geometry = new PolylineOptions();
            var latLngs = coordinate.Split({' '});
            foreach (var latLng in latLngs)
            {
                double lat = 0;
                double lng = 0;
                var arr = latLng.Split({','});
                double.TryParse(arr[0], out lat);
                double.TryParse(arr[1], out lng);
                geometry.Add(new LatLng(lat, lng));
            }
            Polyline polyline = mMap.AddPolyline(geometry);
            // Do something with your polyline
        }
    }
    
    file.Close();
    

提交回复
热议问题