-1
我是新来的mapview,我想显示用户的当前位置,并获取方向到我想修复目标的地图,但源不是修复。 我使用CLLocation类获取当前位置。 现在我想解决目标,并使其禁用和不可编辑。显示用户在ios中的位置和方向使用mkmapview
请给我一些提示如何做到这一点。
感谢,
我是新来的mapview,我想显示用户的当前位置,并获取方向到我想修复目标的地图,但源不是修复。 我使用CLLocation类获取当前位置。 现在我想解决目标,并使其禁用和不可编辑。显示用户在ios中的位置和方向使用mkmapview
请给我一些提示如何做到这一点。
感谢,
首先让你的视图控制器实现MKMapViewDelegate协议和声明的属性,你将需要:
@property (nonatomic, retain) MKMapView *mapView; //this is your map view
@property (nonatomic, retain) MKPolyline *routeLine; //your line
@property (nonatomic, retain) MKPolylineView *routeLineView;
在viewDidLoad中然后(例如,或任何你初始化)
//初始化您的地图视图并将其添加到您的视图层次结构中 - 将其委托设置为se LF *
CLLocationCoordinate2D coordinateArray[2];
coordinateArray[0] = CLLocationCoordinate2DMake(lat1, lon1);
coordinateArray[1] = CLLocationCoordinate2DMake(lat2, lon2);
self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:2];
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
[self.mapView addOverlay:self.routeLine];
然后实现MKMapViewDelegate的方法 - (MKOverlayView *)的MapView:viewForOverlay:
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if(overlay == self.routeLine)
{
if(nil == self.routeLineView)
{
self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];
self.routeLineView.fillColor = [UIColor redColor];
self.routeLineView.strokeColor = [UIColor redColor];
self.routeLineView.lineWidth = 5;
}
return self.routeLineView;
}
return nil;
}
你只是想显示在图形页面2的位置和你想要展现的特殊途径2地址? –
@HimanshuMoradiya是 –
检查此链接可能会帮助你。 [http://stackoverflow.com/questions/29319643/how-to-draw-a-route-between-two-locations-using-mapkit-in-swift] – Aravi