iOS的高德地图标注特定位置

在开发时有时候遇到项目里面需要展示公司的位置,这时如果导入百度地图什么的就太浪费资源,而且还占内存

这时只要调用自动高德地图的就行了

自己写一个控制器,导入框架

现在导入系统框架只要多打次就能出来了,没必要去link添加

 1 #import "MapViewCtl.h"
 2 #import <CoreLocation/CoreLocation.h>
 3 #import <MapKit/MapKit.h>
 4 
 5 //获取屏幕 宽度、高度
 6 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
 7 #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
 8 
 9 @interface MapViewCtl ()<MKMapViewDelegate>
10 {
11     MKMapView *mapView;
12 }
13 @property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;
14 @end
15 
16 @implementation MapViewCtl
17 
18 - (void)viewDidLoad {
19     [super viewDidLoad];
20     mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
21 
22     mapView.mapType = MKMapTypeStandard;
23     
24     CLLocationCoordinate2D location = CLLocationCoordinate2DMake(22, 111);//纬度,经度
25     float zoomLevel = 0.01;
26     MKCoordinateRegion region = MKCoordinateRegionMake(location, MKCoordinateSpanMake(zoomLevel, zoomLevel));
27     [mapView setRegion:[mapView regionThatFits:region] animated:YES];
28     [self.view addSubview:mapView];
29     
30     MKPointAnnotation *pointAnn = [[MKPointAnnotation alloc]init];
31     pointAnn.coordinate = location;
32     pointAnn.title = @"某某有限公司";
33     pointAnn.subtitle = @"某某地址";
34     [mapView addAnnotation:pointAnn];
35     [mapView selectAnnotation:pointAnn animated:YES];
36     
37 }

 

如果不知道怎么查经纬度的,可以参考这个 http://www.doc88.com/p-3157554808098.html

获取到的经纬度是  (经度,纬度),填到 

CLLocationCoordinate2DMake(22, 111)时,要倒过来填  (纬度,经度)

 

posted @ 2016-02-04 16:03  CUG  阅读(1892)  评论(0编辑  收藏  举报