大家好,又见面了,我是你们的朋友全栈君。
在开发时有时候遇到项目里面需要展示公司的位置,这时如果导入百度地图什么的就太浪费资源,而且还占内存
这时只要调用自动高德地图的就行了
自己写一个控制器,导入框架
现在导入系统框架只要多打次就能出来了,没必要去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)时,要倒过来填 (纬度,经度)
转载于:https://www.cnblogs.com/fcug/p/5181811.html
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/143439.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有