ios中地图
参考文章 http://blog.csdn.net/tangaowen/article/details/6527901
http://www.cnblogs.com/tangbinblog/archive/2012/07/11/2586715.html
http://www.cocoachina.com/newbie/basic/2011/1014/3367.html
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h> #import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<CLLocationManagerDelegate,MKMapViewDelegate>
@property (retain, nonatomic) IBOutlet UITextField *latTxt;
@property (retain, nonatomic) IBOutlet UITextField *lonTxg;
@property (retain, nonatomic) IBOutlet UITextField *heightTxt; @end
#import "ViewController.h"
#import "MapMark.h" @interface ViewController () //定位管理
@property(nonatomic,retain)CLLocationManager *manager;
@property(nonatomic,retain)MKMapView *mapview;
@end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad];
self.manager=[[CLLocationManager alloc] init];
_manager.delegate=self;
_manager.desiredAccuracy=kCLLocationAccuracyBest;
_manager.distanceFilter=1000.0;
[_manager release];
self.mapview=[[MKMapView alloc] initWithFrame:CGRectMake(, , , )];
_mapview.delegate=self;
_mapview.mapType=MKMapTypeStandard;
_mapview.zoomEnabled=YES;
_mapview.showsUserLocation=YES;//调用cclocaiton
[self.view addSubview:_mapview];
[_mapview release];
} -(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[_manager startUpdatingLocation]; } -(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[_manager stopUpdatingLocation];
} #pragma mark -CLLocationManager delegate
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
NSLog(@"__%@",locations);
CLLocation *lc= [locations lastObject];
self.latTxt.text=[NSString stringWithFormat:@"%3.5f",lc.coordinate.latitude];
self.lonTxg.text=[NSString stringWithFormat:@"%3.5f",lc.coordinate.longitude];
self.heightTxt.text=[NSString stringWithFormat:@"%3.5f",lc.altitude]; //设置显示区域
MKCoordinateRegion region=MKCoordinateRegionMake(lc.coordinate, MKCoordinateSpanMake(0.05, 0.005));
[_mapview setRegion:region animated:YES];
MapMark *mark=[[MapMark alloc] initwithCoordinate:lc.coordinate];
mark.title=@"小A";
mark.subtitle=@""; // 、、39.938, 116.416
CLLocationCoordinate2D l2d;
l2d.latitude=37.78594;
l2d.longitude=-122.40717;
MapMark *mark1=[[MapMark alloc] initwithCoordinate:l2d];
mark1.title=@"小b";
mark1.subtitle=@"";
[_mapview addAnnotation:mark];//只是把坐标的资料,放入到集合中。
[_mapview addAnnotation:mark1];
} #pragma mark -map delegate //这个代理方法,会依照坐标资料的集合进行render
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{ NSLog(@"-->vieforannotation-->%@",annotation);
//判断是否刚添加的标注
if ([annotation isKindOfClass:[MapMark class]]) { static NSString *bridgeAnnotation=@"annotation";
//从缓存中取值
MKPinAnnotationView *view=(MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:bridgeAnnotation];
if (view==nil) {
view=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:bridgeAnnotation] autorelease];
view.pinColor=MKPinAnnotationColorPurple;
view.animatesDrop=YES;
view.canShowCallout=YES;
UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame=CGRectMake(, , , );
[btn setTitle:@"click" forState:UIControlStateNormal];
view.rightCalloutAccessoryView=btn;
}
view.annotation=annotation;//充缓存中取出来重新设置坐标信息
return view; }
return nil; } //点击标记
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
NSLog(@"-->%@",[view.annotation class]);
if ([view.annotation isMemberOfClass:[MapMark class]]) {
UIButton *btn=(UIButton *)[view rightCalloutAccessoryView];
NSLog(@"--->%@",btn);
}
} #define MINIMUM_ZOOM_ARC 0.014 //approximately 1 miles (1 degree of arc ~= 69 miles)
#define ANNOTATION_REGION_PAD_FACTOR 1.15
#define MAX_DEGREES_ARC 360
//size the mapView region to fit its annotations
- (void)zoomMapViewToFitAnnotations:(MKMapView *)mapView animated:(BOOL)animated
{
NSArray *annotations = mapView.annotations;
int count = [mapView.annotations count];
if ( count == ) { return; } //bail if no annotations //convert NSArray of id <MKAnnotation> into an MKCoordinateRegion that can be used to set the map size
//can't use NSArray with MKMapPoint because MKMapPoint is not an id
MKMapPoint points[count]; //C array of MKMapPoint struct
for( int i=; i<count; i++ ) //load points C array by converting coordinates to points
{
CLLocationCoordinate2D coordinate = [(id <MKAnnotation>)[annotations objectAtIndex:i] coordinate];
points[i] = MKMapPointForCoordinate(coordinate);
}
//create MKMapRect from array of MKMapPoint
MKMapRect mapRect = [[MKPolygon polygonWithPoints:points count:count] boundingMapRect];
//convert MKCoordinateRegion from MKMapRect
MKCoordinateRegion region = MKCoordinateRegionForMapRect(mapRect); //add padding so pins aren't scrunched on the edges
region.span.latitudeDelta *= ANNOTATION_REGION_PAD_FACTOR;
region.span.longitudeDelta *= ANNOTATION_REGION_PAD_FACTOR;
//but padding can't be bigger than the world
if( region.span.latitudeDelta > MAX_DEGREES_ARC ) { region.span.latitudeDelta = MAX_DEGREES_ARC; }
if( region.span.longitudeDelta > MAX_DEGREES_ARC ){ region.span.longitudeDelta = MAX_DEGREES_ARC; } //and don't zoom in stupid-close on small samples
if( region.span.latitudeDelta < MINIMUM_ZOOM_ARC ) { region.span.latitudeDelta = MINIMUM_ZOOM_ARC; }
if( region.span.longitudeDelta < MINIMUM_ZOOM_ARC ) { region.span.longitudeDelta = MINIMUM_ZOOM_ARC; }
//and if there is a sample of 1 we want the max zoom-in instead of max zoom-out
if( count == )
{
region.span.latitudeDelta = MINIMUM_ZOOM_ARC;
region.span.longitudeDelta = MINIMUM_ZOOM_ARC;
}
[mapView setRegion:region animated:animated];
} - (void)viewWillAppear:(BOOL)animated
{
[self zoomMapViewToFitAnnotations:_mapview animated:animated];
//or maybe you would do the call above in the code path that sets the annotations array
} - (void)dealloc {
[_latTxt release];
[_lonTxg release];
[_heightTxt release];
[super dealloc];
}
@end
其中
ios中地图的更多相关文章
- ios中地图定位
#import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> @interface ViewController ...
- iOS中的地图和定位
文章摘自http://www.cnblogs.com/kenshincui/p/4125570.html#location 如有侵权,请联系删除. 概览 现在很多社交.电商.团购应用都引入了地图和定 ...
- IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息
IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息 /**当获取到定位的坐标后,回调函数*/ - (void)didUpdateBMKUserLocation:(BMKUserLocati ...
- iOS开发中地图与定位
不管是QQ还是微信的移动client都少不了定位功能,之前在微信demo中没有加入定位功能,今天就写个定位的小demo来了解一下定位和地图的东西. 地图和定位看上去是挺高大上一东西.其有使用方法比Ta ...
- iOS百度地图SDK集成详细步骤
1.iOS百度地图下载地址 http://developer.baidu.com/map/index.php?title=iossdk/sdkiosdev-download 根据需要选择不同的版本 ...
- iOS原生地图开发指南续——大头针与自定义标注
iOS原生地图开发指南续——大头针与自定义标注 出自:http://www.sxt.cn/info-6042-u-7372.html 在上一篇博客中http://my.oschina.net/u/23 ...
- Cordoval在iOS中的运用整理
一:关于Cordoval理论知识 1:PhoneGap是手机平台上流行的一款中间件.它构建在各种手机平台所提供的WebView(浏览器内核)组件的基础之上,使用javascript语言对应用开发者提供 ...
- iOS开发----地图与导航--定位和位置信息获取
要实现地图.导航功能,往往需要先熟悉定位功能,在iOS中通过Core Location框架进行定位操作.Core Location自身可以单独使用,和地图开发框架MapKit完全是独立的,但是往往地图 ...
- iOS原生地图开发详解
在上一篇博客中:http://my.oschina.net/u/2340880/blog/414760.对iOS中的定位服务进行了详细的介绍与参数说明,在开发中,地位服务往往与地图框架结合使用,这篇博 ...
随机推荐
- win8 中如何删除 共享文件夹 用户名和密码
在访问共享文件夹时我们都喜欢选中记住用户名和密码,可是有时候密码输入错误或者密码修改了,这时就需要我们删除或则修改先前记住的用户名和密码记录. 首先进入:控制面板\所有控制面板项\凭据管理器 选择wi ...
- OC-字符串中大小写字母转换
一般语言中的大小写转换都会提供的有默认的函数,不过闲来无事,简单的模仿实现了一下: 系统中默认的大小写转换: NSString *name=@"博客园-FlyElephant"; ...
- 已知(x,y,z,yaw,pitch,roll)如何得到4*4的转换矩阵?
作者:Nicholas链接:https://www.zhihu.com/question/41514206/answer/104827395来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商 ...
- oracle sqlplus登陆命令
1.语法: {<username>[/<password>][@<connect_identifier>] | / }[AS {SYSDBA | SYSOPER ...
- RAMPS1.4 3d打印控制板接线与测试4
如果之前的操作都顺利,现在就可以插上USB线,打开printrun上位机软件了.mega2560刚刚接通电源时,RAMPS板子上的LED1(绿色)会闪几下.这说明mega2560板子中的固件正在启动. ...
- Pandas Series笔记
1.指向单元素的,类型为元素的类型 2.指向多个元素的,类型为Series 3.如果用索引切片,索引是非整型的,实际按照索引顺序取值,且包含末端 4.如果指定的索引不存在,则会报错 5.可以根据元素的 ...
- HTTP协议中源端口和目标端口的问题
[提问] How is source port for HTTP determined? Is there ever collision in NAT? I know that when a HT ...
- jquery easyui tree异步加载子节点
easyui中的树可以从标记中建立,也可以通过指定一个URL属性读取数据建立.如果想建立一棵异步树,需要为每个节点指定一个id属性值,这样在加载数据时会自动向后台传递id参数. <ul id=& ...
- maven 打包可执行jar的方法
转自:http://blog.csdn.net/johnnywww/article/details/7964326 1.修改pom.xml增加如下内容 <plugin> <group ...
- Hbase master启动报错:Failed construction of Master: class org.apache.hadoop.hbase.master.HMaster Caused by: java.net.UnknownHostException:
Hbase master启动报错: java.lang.RuntimeException: Failed construction of Master: class org.apache.hadoop ...