参考:http://blog.sina.com.cn/s/blog_9e8867eb0101dt76.html

首先在MapView.h中

#import <MapKit/MapKit.h>

@interface MapView : UIView<MKMapViewDelegate> {

	MKMapView* mapView;

}

@property (nonatomic, retain) MKMapView* mapView;
-(void) drawline: (NSArray*)nowRoadArrary;
@end

在MapView.m 中

#import "MapView.h"

@implementation MapView

@synthesize mapView;
-(void) drawline: (NSArray*)nowRoadArrary
{
// 将array中的信息点转换成CLLocationCoordinate2D数组
CLLocationCoordinate2D coords[nowRoadArrary.count]; int i = 0;
for (NSDictionary *newDic in nowRoadArrary) {
CLLocationCoordinate2D annotationCoord;
id lat = [newDic objectForKey:@"latitude"];
annotationCoord.latitude = [lat doubleValue];
annotationCoord.longitude = [[newDic objectForKey:@"longitude"] doubleValue];
coords[i] = annotationCoord;
i++;
} //用MKPolyline画线并作为overlay添加进mapView
MKPolyline *cc = [MKPolyline polylineWithCoordinates:coords count:nowRoadArrary.count];
[mapView addOverlay:cc];
} //完成MapView的delegate
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]])
{
      //如果有MKPloylineView的overlay,将其画出
MKPolylineView *lineview=[[MKPolylineView alloc] initWithOverlay:overlay] ;
//路线颜色
lineview.strokeColor=[UIColor colorWithRed:69.0f/255.0f green:212.0f/255.0f blue:255.0f/255.0f alpha:0.9];
lineview.lineWidth=8.0;
return lineview;
}
return nil;
}

调用MapView

- (void)viewDidLoad
{
//初始化
[super viewDidLoad];
MapView *mapView = [[MapView alloc] initWithFrame:
CGRectMake(0, 244, self.view.frame.size.width,800)] ;
[self.view addSubview:mapView]; //调用
NSDictionary *myplace[4]; myplace[0] = [NSDictionary dictionaryWithObjectsAndKeys:
@"32.0816",@"latitude",
@"118.892",@"longitude",
nil]; myplace[1] = [NSDictionary dictionaryWithObjectsAndKeys:
@"32.0856",@"latitude",
@"118.892",@"longitude",
nil];
myplace[2] = [NSDictionary dictionaryWithObjectsAndKeys:
@"32.0716",@"latitude",
@"118.92",@"longitude",
nil];
myplace[3] = [NSDictionary dictionaryWithObjectsAndKeys:
@"32.0766",@"latitude",
@"118.982",@"longitude",
nil]; NSArray *ary = [[NSArray alloc]initWithObjects:myplace[0],myplace[1],myplace[2],myplace[3], nil]; [mapView drawline:ary];
}

[ios]MKMapView中使用MKPolyline画线的更多相关文章

  1. 画线动画——SVG版和纯CSS版

    概述 我们常常在网站中看到一些画线的动画效果,非常炫酷,大多数这种画线动画效果是通过SVG实现的,也有不少是用纯css实现的,下面我总结了一下这2种方法,供以后开发时参考,相信对其他人也有用. 参考资 ...

  2. Android中Path类的lineTo方法和quadTo方法画线的区别

    转载:http://blog.csdn.net/stevenhu_223/article/details/9229337 当我们需要在屏幕上形成画线时,Path类的应用是必不可少的,而Path类的li ...

  3. iOS小画板画线总结

    一:基本画线: 使用贝赛尔曲线画: //创建路径 UIBezierPath* aPath = [UIBezierPath bezierPath]; //设置线宽 aPath.lineWidth = 5 ...

  4. [修复] Firemonkey 画线问题(Android & iOS 平台)

    问题:官方 QC 的一个 Firemonkey 移动平台画线问题: RSP-14309: [iOS & Android] Delphi 10.1 Berlin - drawing proble ...

  5. IOS Quartz 各种绘制图形用法---实现画图片、写文字、画线、椭圆、矩形、棱形等

    // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affec ...

  6. android布局中画线的方法

    1.自定义View画线 http://fariytale.iteye.com/blog/1264225 下面介绍几种简单的方法 2.textView和View画直线 <TextView andr ...

  7. H5中画图标签Canvas---画矩形,画线,画圆,渐变色,图形载入

    一: 1.鼠标监视坐标值 <!DOCTYPE html> <head> <meta charset=UTF-8> <title>canvas的演示< ...

  8. Vue中使用ECharts画散点图加均值线与阴影区域

    [本文出自天外归云的博客园] 需求 1. Vue中使用ECharts画散点图 2. 在图中加入加均值线 3. 在图中标注出阴影区域 实现 实现这个需求,要明确两点: 1. 知道如何在vue中使用ech ...

  9. android中实现在ImageView上随意画线涂鸦

    我实现的思路: 1.继承ImageView类 2.重写onTouchEvent方法,在ACTION_MOVE(即移动时),记录下所经过的点坐标,在ACTION_UP时(即手指离开时,这时一条线已经画完 ...

随机推荐

  1. jmeter 逻辑控制器Logic Controller详解

    Jmeter之逻辑控制器(Logic Controller) 前言: 1. Jmeter官网对逻辑控制器的解释是:“Logic Controllers determine the order in w ...

  2. Lintcode: Heapify && Summary: Heap

    Given an integer array, heapify it into a min-heap array. For a heap array A, A[0] is the root of he ...

  3. cocos代码研究(2)Label学习笔记

    理论部分 Label类继承自Node类,中文翻译文字与字体,通常在应用开发中为模块作为提示和描述的作用,主要有3中不同的创建方式. 1.通过ttf字体包创建,通过指定本地已有的ttf格式的字体文件,创 ...

  4. 《Bilateral Multi-Perspective Matching for Natural Language Sentences》(句子匹配)

    问题: Natural language sentence matching (NLSM),自然语言句子匹配,是指比较两个句子并判断句子间关系,是许多任务的一项基本技术.针对NLSM任务,目前有两种流 ...

  5. Filter过滤器与Session会话跟踪技术

    Filter过滤器 适用场景 1.为web应用程序的新功能建立模型(可被添加到web应用程序中或者从web应用程序中删除而不需要重写基层应用程序代码)2.用户授权Filter:负责检查用户请求,根据请 ...

  6. Spring 问题总结

    Spring问答Top 25:http://www.importnew.com/15851.html [Java面试五]Spring总结以及在面试中的一些问题.:http://www.cnblogs. ...

  7. MySQL数据库----单表查询

    先创建表 #创建表 create table employee( id int not null unique auto_increment, name varchar(20) not null, s ...

  8. Linux学习笔记之Centos7安装GNOME桌面环境

    最小化安装Centos7,系统默认是命令行界面,如果像我一样有特殊需求,这时就需要我们手动来安装用户图形界面了. 1.查看一下当前的运行级别和可以安装的group. systemctl get-def ...

  9. Jsp中如何通过Jsp调用Java类中的方法

    Jsp中如何通过Jsp调用Java类中的方法 1.新建一个项目,在src文件夹下添加一个包:如:cn.tianaoweb.com; 2.再在包中添加一个类:如 package com; public ...

  10. jdbc连接池c3p0/dbcp强制连接超过设置时间后失效

    通常来说,各种技术实现的优化参数或者选项或者歪门邪道之所以能被想出来,通常是因为开发者或者实现的贡献者曾经遇到过导致此结果的问题,所以才出了对应的策略选项. 在有些情况下,比如存在客户端或者服务端连接 ...