大佬教程收集整理的这篇文章主要介绍了iPhone:如何在MapKit两点之间画线?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经google了,但是找不到一些合适的解决方案,因为我发现这个解决方案是用数组点数来绘制叠加,但是我没有这两点之间的点数.
只需两点,并希望在这两点之间画线.
请帮忙.
@property (nonatomic,retain) MKMapView *mapView; //this is your map view @property (nonatomic,retain) MKPolyline *routeLine; //your line @property (nonatomic,retain) MKPolylineView *routeLineView; //overlay view
然后在viewDidLoad中(例如,或者你初始化的地方)
//initialize your map view and add it to your view hierarchy - **set its delegate to self*** 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 @R_674_8337@ant 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点或更多点来说,这是非常简单的.
以上是大佬教程为你收集整理的iPhone:如何在MapKit两点之间画线?全部内容,希望文章能够帮你解决iPhone:如何在MapKit两点之间画线?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。