【发布时间】:2016-02-17 21:31:01
【问题描述】:
我正在扩展 @https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/maps/map-overlay/polyline/ 提供的示例,以向我的地图添加多条折线。
单条折线一切正常,但是当我添加第二条折线或在注释旁边添加折线时,GetOverlayRenderer 出错并显示错误
"Value cannot be null.Parameter name: polyline"
网上出错了:
polylineRenderer = new MKPolylineRenderer (overlay as MKPolyline);
当我查看覆盖对象时,它是:
{MapKit.MKOverlayWrapper}
BoundingMapRect: {{{62634939.7333333, 111606556.311973}, {745654.044444449, 848491.772016793}}}
Coordinate: {CoreLocation.CLLocationCoordinate2D}
Handle: 0x791ca560
Non-public members:
我不明白为什么它适用于一条折线,但是当我向地图添加任何其他内容时,它会失败(也是第一次通过该方法)
这是发生错误的整个方法。我可以提供更多代码,但它只用一行就可以正常工作,而不是两行。 (我遍历一个对象列表...如果有 1,那很好。如果有 2,它会失败)。
MKOverlayRenderer GetOverlayRenderer (MKMapView mapView, IMKOverlay overlay)
{
if (polylineRenderer == null) {
try
{
polylineRenderer = new MKPolylineRenderer (overlay as MKPolyline);
polylineRenderer.FillColor = UIColor.Blue;
polylineRenderer.StrokeColor = UIColor.Red;
polylineRenderer.LineWidth = 3;
polylineRenderer.Alpha = 0.4f;
}
catch (Exception ex) {
}
}
return polylineRenderer;
}
【问题讨论】:
-
这可能是一个错误。如果你能把它拉上拉链寄过来,我会快速看一下?如果是这样,我的详细信息在我的个人资料中。
-
我会直接给你发邮件,但是这里有其他感兴趣的人可以使用的链接...drive.google.com/file/d/0B5Tg3f2jpNBpbGFzVTFpZ2JQNFk/view这是一个稍微修改过的食谱版本(只是将 GPS 坐标移到我的区域进行演示与客户)。它适用于一个叠加层(注释掉 iOS 项目中 CustomMapRenderer.cs 的第 55 行)。如果添加第二个叠加层,它也不会显示。
标签: xamarin.ios mkmapview xamarin.forms mkpolyline