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

时间:2021-01-01 00:41:06

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

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

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

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

 #import "MapViewCtl.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h> //获取屏幕 宽度、高度
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) @interface MapViewCtl ()<MKMapViewDelegate>
{
MKMapView *mapView;
}
@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;
@end @implementation MapViewCtl - (void)viewDidLoad {
[super viewDidLoad];
mapView = [[MKMapView alloc]initWithFrame:CGRectMake(, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; mapView.mapType = MKMapTypeStandard; CLLocationCoordinate2D location = CLLocationCoordinate2DMake(, );//纬度,经度
float zoomLevel = 0.01;
MKCoordinateRegion region = MKCoordinateRegionMake(location, MKCoordinateSpanMake(zoomLevel, zoomLevel));
[mapView setRegion:[mapView regionThatFits:region] animated:YES];
[self.view addSubview:mapView]; MKPointAnnotation *pointAnn = [[MKPointAnnotation alloc]init];
pointAnn.coordinate = location;
pointAnn.title = @"某某有限公司";
pointAnn.subtitle = @"某某地址";
[mapView addAnnotation:pointAnn];
[mapView selectAnnotation:pointAnn animated:YES]; }

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

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

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