简体   繁体   English

标记已加载到地图上,但折线未显示在谷歌地图上,代码中没有错误

[英]markers are loaded on map but polylines are not showing up on google map with no error in code

I wrote the code according to documentation for polylines and i am not getting any error in code or no exception is thrown by code.我根据折线的文档编写了代码,我没有收到任何代码错误或代码没有抛出异常。 even the app is running fine but polylines which should show up is not loading on map in my android app.即使应用程序运行良好,但应显示的折线未加载到我的 android 应用程序的地图上。

foreach (var route in routeList)
                {
                    if (route.RouteSegmentPoints != null)
                    {

                        Polyline polyline;
                        int color = Android.Graphics.Color.Black;
                        PolylineOptions poly = 
Utils.GetPolyLineOptions(color, 100, true, 100);
                        polyline = _map.AddPolyline(poly);
                        for (int i=0;i<route.RouteSegmentPoints.Count;i++)
                        {
                            point = new 
LatLng(Convert.ToDouble(route.RouteSegmentPoints[i].Latitude), 
Convert.ToDouble(route.RouteSegmentPoints[i].Longitude));
                            //endPoint = new 
LatLng(Convert.ToDouble(route.RouteSegmentPoints[i+1].Latitude), 
Convert.ToDouble(route.RouteSegmentPoints[i+1].Longitude));
                            poly.Add(point);
                        }



                        //System.Console.WriteLine("single Route");
                    }
                }

If anyone knows about solution please let me know thanks in advance.如果有人知道解决方案,请提前告诉我谢谢。

You should be assigning values to poly before adding it to the _map , so the values you add to it aren't passed in.您应该在将poly添加到_map之前为其分配值,因此不会传入您添加到它的值。

foreach (var route in routeList)
{
    if (route.RouteSegmentPoints != null)
    {
        Polyline polyline;
        int color = Android.Graphics.Color.Black;
        PolylineOptions poly = Utils.GetPolyLineOptions(color, 100, true, 100);
        for (int i=0;i<route.RouteSegmentPoints.Count;i++)
        {
            point = new 
LatLng(Convert.ToDouble(route.RouteSegmentPoints[i].Latitude), 
Convert.ToDouble(route.RouteSegmentPoints[i].Longitude));
            poly.Add(point);
        }
        polyline = _map.AddPolyline(poly);
    }
}

If that doesn't work either, you could try wrapping the last line from my code to Run On the Ui Thread because depending on the thread this code is being executed on it may not be updating the UI:如果这也不起作用,您可以尝试将我的代码的最后一行包装到在 Ui 线程上运行,因为根据正在执行此代码的线程,它可能不会更新 UI:

Activity.RunOnUiThread(() => {
    polyline = _map.AddPolyline(poly);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM