Oc LocateMap(地图定位)
来源:互联网 发布:平面广告图制作软件 编辑:程序博客网 时间:2024/06/09 17:35
!
一、 添加库文件
二、写入控件
三、实现代码
#import "ViewController.h"#import <MapKit/MapKit.h>//地图#import <CoreLocation/CoreLocation.h>//定位@interface ViewController ()<MKMapViewDelegate>//纬度字段@property (weak,nonatomic)IBOutletUITextField *latitudeField;//经度字段@property (weak,nonatomic)IBOutletUITextField *longitudeField;//地图 VIew@property (weak,nonatomic)IBOutletMKMapView *mapView;//原位置- (IBAction)goClicked:(UIButton *)sender;@end/** 纬度为南纬90-0-北纬90 经度为西经180-本出子午线(0度)-东经180 市界的地理坐标为:北纬39”26’至41”03’,东经115”25’至 117”30’。 北京天安门广场的经纬度(东经:116°23′17〃,北纬:39°54′27〃 北京市区坐标为:北纬39.9”,东经116. 3”。 各郊区、县的地理坐标为: 房山区,北纬 39. 6”,东经115.9”; 门头沟区,北纬39.6o”,东经115.9; 大兴县,北纬39.7”,东经116.3”; 通县,北纬39.8”,东经116.6”, 顺义县,北纬40.l”,东经116.6”; 平谷县,北纬40 1”,东经117.1” 昌平县,北纬40.2”,东经116.2”; 怀柔县,北纬40.3”,东经116.6”; 密云县,北纬40.3”,东经116 8”; 延庆县,北纬40.4”,东经115.9”。 纬度:37.7858 经度 -122.406 */@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; /**类型 MKMapTypeStandard = 0,可映射类型标准 MKMapTypeSatellite, 可映射类型卫星 MKMapTypeHybrid, 可映射类型混合(普通地图覆盖于卫星云图之上) MKMapTypeSatelliteFlyover MK地图类型的国家立交桥(3D立体卫星) MKMapTypeHybridFlyover MK地图型混合飞行(3D立体混合) */ // 设置地图的显示风格,此处设置使用标准地图 self.mapView.mapType = MKMapTypeStandard; // 设置地图可缩放 self.mapView.zoomEnabled =YES; // 设置地图可滚动 self.mapView.scrollEnabled =YES; // 设置地图可旋转 self.mapView.rotateEnabled =YES; // 设置显示用户当前位置 self.mapView.showsUserLocation =YES; // 为MKMapView设置delegate self.mapView.delegate =self; // 调用自己实现的方法设置地图的显示位置和显示区域 [self locateToLatitude:23.126272 longitude:113.395568]; NSLog(@"用户当前是否位于地图中:%d" ,self.mapView.userLocationVisible);}- (IBAction)goClicked:(UIButton *)sender{ // 关闭两个文本框的虚拟键盘 [self.latitudeField resignFirstResponder]; [self.longitudeField resignFirstResponder]; NSString* latitudeStr = self.latitudeField.text; NSString* longtitudeStr = self.longitudeField.text; // 如果用户输入的经度、纬度不为空 if (latitudeStr !=nil && latitudeStr.length >0 && longtitudeStr != nil && longtitudeStr.length >0) { // 调用自己实现的方法设置地图的显示位置和显示区域 [self locateToLatitude:latitudeStr.floatValue longitude:longtitudeStr.floatValue]; }}#pragma mark - 显示位置和显示区域 --封装- (void)locateToLatitude:(CGFloat)latitude longitude:(CGFloat)longitude{ // 设置地图中心的经、纬度 CLLocationCoordinate2D center = {latitude , longitude}; // 也可以使用如下方式设置经、纬度 //center.latitude = latitude; //center.longitude = longitude; // 设置地图显示的范围, MKCoordinateSpan span; // 地图显示范围越小,细节越清楚 span.latitudeDelta = 0.01; span.longitudeDelta = 0.01; // 创建MKCoordinateRegion对象,该对象代表了地图的显示中心和显示范围。 MKCoordinateRegion region = {center,span}; // 设置当前地图的显示中心和显示范围 [self.mapView setRegion:region animated:YES];}
阅读全文
0 0
- Oc LocateMap(地图定位)
- iOS LocateMap(地图定位)~demo
- oc地图
- 地图定位
- 地图定位
- 地图定位
- 地图定位
- 地图、定位
- 地图定位
- 地图定位
- 地图定位
- 地图定位
- 地图定位
- 地图定位
- 地图定位
- 地图定位
- 地图定位
- 地图定位
- 学生的成绩
- CodeForces
- NOIP2016普及组复赛买铅笔
- 24点
- [BZOJ]1426 收集邮票 概率与期望
- Oc LocateMap(地图定位)
- codeforces 864B
- MVP学习笔记
- 页面滚动条的实现
- mysql修改表,添加列,修改类型,修改列,修改表名,修改表的字符集,sql添加记录,重启mysql命令
- Codeforces Round #443 (Div. 2)D. Teams Formation详解
- Python——二叉树的深度遍历
- Oc CLGeocoder(地图解析)
- Swing 工具常用总结