【问题标题】:Polyline not shown on GoogleMap Xamarin.AndroidGoogleMap Xamarin.Android 上未显示折线
【发布时间】:2018-05-07 13:28:38
【问题描述】:

我正在尝试使用 Xamarin 为 Android 构建 ActivityTracker 应用程序。我已经可以访问 Google Maps Api 并且可以获得当前设备位置。下一步是将我进入折线的位置连接起来,但折线在地图上不可见。

这是我试过的代码

private Polyline polyline;
public void OnMapReady(GoogleMap map)
    {
        _map = map;
        _map.MyLocationEnabled = true;
        _map.TrafficEnabled = true;
        _map.SetIndoorEnabled(true);
        PolylineOptions poly = new PolylineOptions()
            .InvokeColor(Color.Red)
            .InvokeWidth(5)
            .Visible(true)
            .InvokeZIndex(30);
        poly.Add(new LatLng(95, 50));
        poly.Add(new LatLng(90, 55));
        poly.Add(new LatLng(100, 50));

        polyline = _map.AddPolyline(poly);
        _map.MyLocationChange += MyLocationChanged; 
    }

【问题讨论】:

    标签: android google-maps xamarin


    【解决方案1】:

    您的代码很好,但折线点的坐标很糟糕:Google Maps using WGS 84 Web Mercator projection with truncated latitudes of Latmax = ±85.05113°,所以坐标 LatLng(95, 50) 没有意义(95 - 太纬度大)和LatLng(90, 55)LatLng(100, 50)。您的坐标应从(-89.99,-179.99)(89.99,179.99)。例如,尝试使用 55, 6070 而不是 95, 90100

    private Polyline polyline;
    public void OnMapReady(GoogleMap map)
        {
            _map = map;
            _map.MyLocationEnabled = true;
            _map.TrafficEnabled = true;
            _map.SetIndoorEnabled(true);
            PolylineOptions poly = new PolylineOptions()
                .InvokeColor(Color.Red)
                .InvokeWidth(5)
                .Visible(true)
                .InvokeZIndex(30);
            poly.Add(new LatLng(55, 50));
            poly.Add(new LatLng(60, 55));
            poly.Add(new LatLng(70, 50));
    
            polyline = _map.AddPolyline(poly);
            _map.MyLocationChange += MyLocationChanged; 
        }
    

    【讨论】:

      猜你喜欢
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多