高德地图根据经纬度画折线, 虚线(以两个点为例)
2015-12-22 12:19
1086 查看
- (void)createBrokenLine
{
CLLocationCoordinate2D commonPolyLineCoords[2];
for (int i =0; i < self.dataParkLaneArr.count; i ++) {
// 点的信息Model
ParkInfo *parkInfo = self.dataParkLaneArr[i];
// 点1 字符串形式的经纬度以逗号分隔;
CGFloat p1Longitude = [parkInfo.entrance componentsSeparatedByString:@","][0].floatValue;
CGFloat p1Latitude = [parkInfo.entrance componentsSeparatedByString:@","][1].floatValue;
// 点2
CGFloat p2Longitude = [parkInfo.exitus componentsSeparatedByString:@","][0].floatValue;
CGFloat p2Latitude = [parkInfo.exitus componentsSeparatedByString:@","][1].floatValue;
commonPolyLineCoords[0].longitude = p1Longitude;
commonPolyLineCoords[0].latitude = p1Latitude;
commonPolyLineCoords[1].longitude = p2Longitude;
commonPolyLineCoords[1].latitude = p2Latitude;
}
MAPolyline *commonPoly = [MAPolylinepolylineWithCoordinates:commonPolyLineCoordscount:2];
[self.mapViewaddOverlay:commonPoly];
}
// MAMapViewDelegate
- (MAOverlayView *)mapView:(MAMapView *)mapView viewForOverlay:(id<MAOverlay>)overlay
{
if ([overlayisKindOfClass:[MAPolylineclass]]) {
MAPolylineView *lineView = [[MAPolylineViewalloc] initWithPolyline:overlay];
// 把实线变成虚线加下边的三行代码
lineView.lineDashPhase =10; // 1
NSArray* array = [NSArrayarrayWithObjects:[NSNumbernumberWithInt:15] , [NSNumbernumberWithInt:15],nil]; // 2
lineView.lineDashPattern = array; // 3
lineView.lineWidth =8.f;
lineView.strokeColor = [UIColorcolorWithRed:0.318green:0.404blue:0.972alpha:1.000];
lineView.lineJoin =kCGLineJoinMiter;
lineView.lineCap =kCGLineCapButt;
return lineView;
}
returnnil;
}
{
CLLocationCoordinate2D commonPolyLineCoords[2];
for (int i =0; i < self.dataParkLaneArr.count; i ++) {
// 点的信息Model
ParkInfo *parkInfo = self.dataParkLaneArr[i];
// 点1 字符串形式的经纬度以逗号分隔;
CGFloat p1Longitude = [parkInfo.entrance componentsSeparatedByString:@","][0].floatValue;
CGFloat p1Latitude = [parkInfo.entrance componentsSeparatedByString:@","][1].floatValue;
// 点2
CGFloat p2Longitude = [parkInfo.exitus componentsSeparatedByString:@","][0].floatValue;
CGFloat p2Latitude = [parkInfo.exitus componentsSeparatedByString:@","][1].floatValue;
commonPolyLineCoords[0].longitude = p1Longitude;
commonPolyLineCoords[0].latitude = p1Latitude;
commonPolyLineCoords[1].longitude = p2Longitude;
commonPolyLineCoords[1].latitude = p2Latitude;
}
MAPolyline *commonPoly = [MAPolylinepolylineWithCoordinates:commonPolyLineCoordscount:2];
[self.mapViewaddOverlay:commonPoly];
}
// MAMapViewDelegate
- (MAOverlayView *)mapView:(MAMapView *)mapView viewForOverlay:(id<MAOverlay>)overlay
{
if ([overlayisKindOfClass:[MAPolylineclass]]) {
MAPolylineView *lineView = [[MAPolylineViewalloc] initWithPolyline:overlay];
// 把实线变成虚线加下边的三行代码
lineView.lineDashPhase =10; // 1
NSArray* array = [NSArrayarrayWithObjects:[NSNumbernumberWithInt:15] , [NSNumbernumberWithInt:15],nil]; // 2
lineView.lineDashPattern = array; // 3
lineView.lineWidth =8.f;
lineView.strokeColor = [UIColorcolorWithRed:0.318green:0.404blue:0.972alpha:1.000];
lineView.lineJoin =kCGLineJoinMiter;
lineView.lineCap =kCGLineCapButt;
return lineView;
}
returnnil;
}
相关文章推荐
- spi demo code 及 使用注意事项
- 编译安装MySQL
- [从头学数学] 第13节 分类与整理
- iOS怎么获取设置是否开启消息通知
- php unserialize报错解决记录
- 【jQuery】使用$.extend()扩展Object对象
- js知识总结
- GCD调度组的使用
- [翻译]How can I learn to program?
- fprintf() stderr std out stdin
- gradle配置
- JavaScript+CSS无限极分类效果完整实现方法
- sql语句
- 最全苹果发行地、固件版本
- Keil 代码 变量等大小查看方法
- IT原创好博
- 去除移动端点击事件出现的背景框 tap-highlight-color
- SpringBoot初探(二)——打成war和自动部署
- 每天一个Linux命令(1) ls
- MySQLDump在使用之前一定要想到的事情 [转载]