美文网首页
4.在地图上两个坐标点之间画一条直线

4.在地图上两个坐标点之间画一条直线

作者: 流沙3333 | 来源:发表于2017-03-10 14:11 被阅读121次

- (void)drawTestLine

{

CLLocation*location0 = [[CLLocationalloc]initWithLatitude:39.954245longitude:116.312455];//北京杭州

CLLocation*location1 = [[CLLocationalloc]initWithLatitude:30.247871longitude:120.127683];

NSArray*array = [NSArrayarrayWithObjects:location0, location1,nil];

[self  drawLineWithLocationArray:array];

}

- (void)drawLineWithLocationArray:(NSArray*)locationArray

{

int pointCount = [locationArray count];

CLLocationCoordinate2D* coordinateArray = (CLLocationCoordinate2D*)malloc(pointCount *sizeof(CLLocationCoordinate2D));

for(int i =0; i < pointCount; ++i) {

CLLocation*location = [locationArray objectAtIndex:i];

coordinateArray[i] = [location coordinate];

}

self.routeLine= [MKPolylinepoly lineWithCoordinates:coordinateArray count:pointCount];

[self.mapView setVisibleMapRect:[self.routeLineboundingMapRect]];

[self.mapView addOverlay:self.routeLine];

free(coordinateArray);

coordinateArray =NULL;

}

/**

*当添加一个覆盖层数据模型到地图上时,地图会调用这个方法,查找对应的覆盖层视图(渲染图层)

*

*  @param mapView地图

*  @param overlay覆盖层数据模型

*

*  @return覆盖层视图

*/

- (MKOverlayRenderer*)mapView:(MKMapView*)mapView rendererForOverlay:(id)overlay

{

if( [overlayisKindOfClass:[MKPolylineclass]]) {

MKPolylineRenderer*routeLineView = [[MKPolylineRenderer alloc]initWithPolyline:self.routeLine];

//self.routeLineView.fillColor = [UIColor redColor];

routeLineView.strokeColor= [UIColorredColor];

routeLineView.lineWidth=1;

return routeLineView;

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event{

UITouch* t = [touches allObjects].firstObject;

CGPoint point = [t locationInView:self.mapView];

CLLocationCoordinate2D coordinate2D = [self.mapView convertPoint:point toCoordinate FromView:self.mapView];

CLLocation* location =

[[CLLocation alloc]initWithLatitude:coordinate2D.latitude  longitude:coordinate2D.longitude];

if(_lastLocation2) {

CLLocationDistance distance = [location  distanceFromLocation:_lastLocation2];

//将用户连续两次点击地图时的点画一条直线

//NSArray *array = [NSArray arrayWithObjects:location, _lastLocation2,nil];

//[self drawLineWithLocationArray:array];

}else{

_lastLocation2= location;

}

//每点击一下地图,就在该位置和用户的位置画一条直线

//NSArray

*array = [NSArray arrayWithObjects:location,

self.mapView.userLocation.location, nil];

//[self drawLineWithLocationArray:array];

}

相关文章

  • 4.在地图上两个坐标点之间画一条直线

    - (void)drawTestLine { CLLocation*location0 = [[CLLocatio...

  • Canvas的基本使用

    1.基本使用 HTML JavaScript 2.画一条直线 3.画多边形 4.分开画两条直线 ** 4.1假如不...

  • Elasticsearch geo_polygon 按多边形范围

    ES 通过geo_polygon,在地图上画一个多边形,搜索包含在多边形内部的坐标点。 例子: 在地图上画一个多边...

  • 线表入门-如何优雅的画一条直线

    前言 看到题目,估计大家都笑了,直线有什么好学的,拿起鼠标点两下不就行了么? 在EXCEL中手动画一条线非常简单,...

  • 初中数学九条基本事实

    1.两点确定一条直线 2.两点之间线段最短 3.过一点有且只有一条直线与已知直线垂直 4.两条直线被第三条直线所截...

  • 画一条直线

    最近在学书法,第一堂课第一个笔画就是横。 横不是一条直线。 人生也不是一条直线。 没有人是按照理想的轨迹慢慢前行的...

  • canvas基本操作

    画一条直线 画一个矩形 画一个三角形 画一个圆

  • 浅显易懂的《垂直与平行线》

    (一)线段、射线、直线的区别 1.过一个点,只能画一条直线。 {×} 2.经过两点,只能画出一条直线。 {√} 3...

  • 数学是美丽的童话

    1 “当一条直线在另一条直线上升起时,在他们之间形成了两个相邻的、一样的角,这两个一样的角就是直角,那条竖起来的直...

  • 都知道 两点之间直线最短 可是 连接两个城市之间的路 从来 不是一条直线 总是因为各种原因 而弯来弯去 甚至 绕来...

网友评论

      本文标题:4.在地图上两个坐标点之间画一条直线

      本文链接:https://www.haomeiwen.com/subject/epnngttx.html