Map1
2015-12-09 21:48
225 查看
1.导入地图的库:Mapkit.framework
2.在导入到工程.m中 导入对应的系统文件 如:
<MapKit/MapKit.h>
MKMapView *mapView = [[MKMapView
alloc]initWithFrame:self.view.bounds];
mapView.delegate = self;
//地图样式
mapView.mapType = MKMapTypeHybrid;
// //缩放
// mapView.zoomEnabled = NO;
// //滑动
// mapView.scrollEnabled = NO;
//显示当前位置,位置发生变化时候会显示当前位置
mapView.showsUserLocation =
YES;
[self.view
addSubview:mapView];
//标注 (大头针)
自定义类
//添加的标注得自定义,同时实现<#(id<MKAnnotation>)#>协议
MyAnnotation *ann = [[MyAnnotation
alloc]init];
ann.coordinate =
CLLocationCoordinate2DMake(37.192279, -122.015586);
ann.title= @"精英";
ann.subtitle = @"河北四期";
[mapView addAnnotation:ann];
//覆盖物
这里要能显示效果需要调用渲染器-----在MKMapViewDelegate 的代理方法理写
CLLocationCoordinate2D points[4];//个数
points[0] =
CLLocationCoordinate2DMake(37.192279, -122.015586);
points[1] =
CLLocationCoordinate2DMake(30.192279, -122.015586);
points[2] =
CLLocationCoordinate2DMake(30.192279, -112.015586);
points[3] =
CLLocationCoordinate2DMake(37.192279, -112.015586);
// 闭合曲线
// MKPolygon *gon = [MKPolygon polygonWithCoordinates:points count:4];
// [mapView addOverlay:gon];
//折线
MKPolyline *line = [MKPolyline
polylineWithCoordinates:points count:4];
[mapView addOverlay:line];
//圈圈
MKCircle *circle = [MKCircle
circleWithCenterCoordinate:points[3]
radius:100000];
[mapView addOverlay:circle];
//
}
//给覆盖物渲染颜色 ------------------代理方法
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay {
//判断是哪个类
if ([overlay isKindOfClass:[MKPolygon
class]]) {
MKPolygonRenderer *render = [[MKPolygonRenderer
alloc]initWithPolygon:overlay];
// 画笔颜色
render.strokeColor = [UIColor
redColor];
//填充色
render.fillColor = [UIColor
greenColor];
//线的宽度
render.lineWidth =
3;
return render;
}else if ([overlay
isKindOfClass:[MKPolyline
class]]){
MKPolylineRenderer *render = [[MKPolylineRenderer
alloc]initWithPolyline:overlay];
render.strokeColor = [UIColor
purpleColor];
render.lineWidth =
1;
return render;
}else{
MKCircleRenderer *render = [[MKCircleRenderer
alloc]initWithOverlay:overlay];
render.strokeColor = [UIColor
magentaColor];
render.fillColor = [UIColor
cyanColor];
render.lineWidth =
2;
return render;
}
return nil;
}
// MyAnnotation.h
// MapTest
//
// Created by laoyu on 15/12/9.
// Copyright (c) 2015年 zhiyou. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
//自定义标注,必须实现协议的必选属性
//看到了属性马山想到 set get 方法
@interface MyAnnotation :
NSObject<MKAnnotation>
@property (nonatomic)
CLLocationCoordinate2D coordinate;
@property (nonatomic,
copy) NSString *title;
@property (nonatomic,
copy) NSString *subtitle;
@end
2.在导入到工程.m中 导入对应的系统文件 如:
<MapKit/MapKit.h>
MKMapView *mapView = [[MKMapView
alloc]initWithFrame:self.view.bounds];
mapView.delegate = self;
//地图样式
mapView.mapType = MKMapTypeHybrid;
// //缩放
// mapView.zoomEnabled = NO;
// //滑动
// mapView.scrollEnabled = NO;
//显示当前位置,位置发生变化时候会显示当前位置
mapView.showsUserLocation =
YES;
[self.view
addSubview:mapView];
//标注 (大头针)
自定义类
//添加的标注得自定义,同时实现<#(id<MKAnnotation>)#>协议
MyAnnotation *ann = [[MyAnnotation
alloc]init];
ann.coordinate =
CLLocationCoordinate2DMake(37.192279, -122.015586);
ann.title= @"精英";
ann.subtitle = @"河北四期";
[mapView addAnnotation:ann];
//覆盖物
这里要能显示效果需要调用渲染器-----在MKMapViewDelegate 的代理方法理写
CLLocationCoordinate2D points[4];//个数
points[0] =
CLLocationCoordinate2DMake(37.192279, -122.015586);
points[1] =
CLLocationCoordinate2DMake(30.192279, -122.015586);
points[2] =
CLLocationCoordinate2DMake(30.192279, -112.015586);
points[3] =
CLLocationCoordinate2DMake(37.192279, -112.015586);
// 闭合曲线
// MKPolygon *gon = [MKPolygon polygonWithCoordinates:points count:4];
// [mapView addOverlay:gon];
//折线
MKPolyline *line = [MKPolyline
polylineWithCoordinates:points count:4];
[mapView addOverlay:line];
//圈圈
MKCircle *circle = [MKCircle
circleWithCenterCoordinate:points[3]
radius:100000];
[mapView addOverlay:circle];
//
}
//给覆盖物渲染颜色 ------------------代理方法
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay {
//判断是哪个类
if ([overlay isKindOfClass:[MKPolygon
class]]) {
MKPolygonRenderer *render = [[MKPolygonRenderer
alloc]initWithPolygon:overlay];
// 画笔颜色
render.strokeColor = [UIColor
redColor];
//填充色
render.fillColor = [UIColor
greenColor];
//线的宽度
render.lineWidth =
3;
return render;
}else if ([overlay
isKindOfClass:[MKPolyline
class]]){
MKPolylineRenderer *render = [[MKPolylineRenderer
alloc]initWithPolyline:overlay];
render.strokeColor = [UIColor
purpleColor];
render.lineWidth =
1;
return render;
}else{
MKCircleRenderer *render = [[MKCircleRenderer
alloc]initWithOverlay:overlay];
render.strokeColor = [UIColor
magentaColor];
render.fillColor = [UIColor
cyanColor];
render.lineWidth =
2;
return render;
}
return nil;
}
// MyAnnotation.h
// MapTest
//
// Created by laoyu on 15/12/9.
// Copyright (c) 2015年 zhiyou. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
//自定义标注,必须实现协议的必选属性
//看到了属性马山想到 set get 方法
@interface MyAnnotation :
NSObject<MKAnnotation>
@property (nonatomic)
CLLocationCoordinate2D coordinate;
@property (nonatomic,
copy) NSString *title;
@property (nonatomic,
copy) NSString *subtitle;
@end
相关文章推荐
- 批量导入po接口生成po的代码
- 使用第三方框架 Masonry 实现自动布局
- 电子或通信领域当前的主流技术及其社会需求调查报告
- java 组合关系
- JAVA面向对象编程上重点总结
- 测试用例设计--因果图
- 让UIImageView适应图片的大小
- CCF真题之相邻数对
- scau 9502 ARDF一个变量的问题
- 【高可用HA】Nginx (1) —— Mac下配置Nginx Http负载均衡(Load Balancer)之101实例
- 九度oj-1384-二维数组中的查找
- 表单验证
- 在android wear开发中使用蓝牙调试手表实机
- leetcode -- Rotate List -- 重点
- Unity3D-Unity Remote
- 以太网为什么要限制最小帧长?
- v$event_name
- 安装git
- 03-下载进条.
- Prim算法