2017-01-31 1 views
0

xamarin ios에서 mkMap을 사용하여 경로 선을 그립니다. 내 코드가 올바르게 작동하지만 점 사이의 경로 선이 표시되지 않습니다. 내 코드가 아래에 주어진 나의 첫 번째 사진은 시작 주석 포인트를 표시하고 두 번째 사진은 주석 지점을 종료xamarin ios에서 MkMap을 사용하여 경로가 표시되지 않습니다.

지도보기 코드 보여줍니다

private MKMapView _map; 
     private MapDelegate _mapDelegate; 

    public QiblaCompassVC (IntPtr handle) : base (handle) 
    { 
    } 
    public override void ViewDidLoad() 
    { 
     base.ViewDidLoad(); 
     _map = new MKMapView(mapsView.Bounds) 
     { 
      MapType = MKMapType.Standard, 
      ShowsUserLocation = true, 
      ZoomEnabled = true, 
      ScrollEnabled = true 
     }; 
     //_map = new MKMapView(mapsView.Bounds); 
     // _map.ShowsUserLocation = true; 
     _mapDelegate = new MapDelegate(); 
     _map.Delegate = _mapDelegate; 
     //mapsView.Add(_map); 
     View = _map; 
     var target = new CLLocationCoordinate2D(30.3753, 69.3451); 
     var viewPoint = new CLLocationCoordinate2D(21.3891, 39.8579); 
     var annotation = new mapAnnotation(new CLLocationCoordinate2D(30.3753, 69.3451), "Pakistan", "Countery of love"); 
     _map.AddAnnotation(annotation); 
     var annotation1 = new mapAnnotation(new CLLocationCoordinate2D(21.3891, 39.8579), "Makka", "Allah home"); 
     _map.AddAnnotation(annotation1); 
     var camera = MKMapCamera.CameraLookingAtCenterCoordinate(target, viewPoint, 500); 
     _map.Camera = camera; 
     createRoute(); 
     //CLLocationCoordinate2D coords = new CLLocationCoordinate2D(30.3753, 69.3451); 
     //MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coords.Latitude)); 
     //_map.Region = new MKCoordinateRegion(coords, span); 
    } 

    public void createRoute() 
    { 

     var dict = new NSDictionary(); 
     var orignPlaceMark = new MKPlacemark(new CLLocationCoordinate2D(30.3753, 69.3451), dict); 
     var sourceItem = new MKMapItem(orignPlaceMark); 

     //End at Xamarin Cambridge Office 
     var destPlaceMark = new MKPlacemark(new CLLocationCoordinate2D(21.3891, 39.8579), dict); 
     var destItem = new MKMapItem(destPlaceMark); 

     var request = new MKDirectionsRequest 
     { 
      Source = sourceItem, 
      Destination = destItem, 
      RequestsAlternateRoutes = true, 

     }; 

     var directions = new MKDirections(request); 

     directions.CalculateDirections((response, error) => 
     { 
      if (error != null) 
      { 
       Console.WriteLine(error.LocalizedDescription); 
      } 
      else 
      { 
       //Add each Polyline from route to map as overlay 
       foreach (var route in response.Routes) 
       { 
        _map.AddOverlay(route.Polyline); 
       } 

      } 
     }); 
    } 

MapDelegate 코드 :

class MapDelegate : MKMapViewDelegate 
    { 
     public override MKOverlayRenderer OverlayRenderer(MKMapView mapView, IMKOverlay overlay) 
     { 
      if (overlay is MKPolyline) 
      { 
       var route = (MKPolyline)overlay; 
       var renderer = new MKPolylineRenderer(route) { StrokeColor = UIColor.Blue }; 
       return renderer; 
      } 
      return null; 
     } 
     public override MKOverlayView GetViewForOverlay(MKMapView mapView, IMKOverlay overlay) 
     { 
      if (overlay is MKPolyline) 
      { 
       // return a view for the polygon 
       MKPolyline l_polyline = overlay as MKPolyline; 
       MKPolylineView l_polylineView = new MKPolylineView(l_polyline); 
       MKPolylineRenderer l_polylineRenderer = new MKPolylineRenderer(l_polyline); 

       l_polylineView.FillColor = UIColor.Blue; 
       l_polylineView.StrokeColor = UIColor.Red; 

       return l_polylineView; 
      } 

      return null; 
     } 
    } 

First pic is the Starting point Second pic is ending point

답변

0

문제는 그것이 MKPolyline 함유 래퍼이 그것을 얻는 방법이다

오버레이 파라미터가없는 형태가 아닌 의 상기 GetViewForOverlay 방법 MKPolyline이다 :

MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlayWrapper) 
{ 
    var overlay = Runtime.GetNSObject(overlayWrapper.Handle) as IMKOverlay; 

    ... 
} 

Source from xamarin forum

관련 문제