参考文章  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中地图的更多相关文章

  1. ios中地图定位

    #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> @interface ViewController ...

  2. iOS中的地图和定位

    文章摘自http://www.cnblogs.com/kenshincui/p/4125570.html#location  如有侵权,请联系删除. 概览 现在很多社交.电商.团购应用都引入了地图和定 ...

  3. IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息

    IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息 /**当获取到定位的坐标后,回调函数*/ - (void)didUpdateBMKUserLocation:(BMKUserLocati ...

  4. iOS开发中地图与定位

    不管是QQ还是微信的移动client都少不了定位功能,之前在微信demo中没有加入定位功能,今天就写个定位的小demo来了解一下定位和地图的东西. 地图和定位看上去是挺高大上一东西.其有使用方法比Ta ...

  5. iOS百度地图SDK集成详细步骤

    1.iOS百度地图下载地址 http://developer.baidu.com/map/index.php?title=iossdk/sdkiosdev-download 根据需要选择不同的版本  ...

  6. iOS原生地图开发指南续——大头针与自定义标注

    iOS原生地图开发指南续——大头针与自定义标注 出自:http://www.sxt.cn/info-6042-u-7372.html 在上一篇博客中http://my.oschina.net/u/23 ...

  7. Cordoval在iOS中的运用整理

    一:关于Cordoval理论知识 1:PhoneGap是手机平台上流行的一款中间件.它构建在各种手机平台所提供的WebView(浏览器内核)组件的基础之上,使用javascript语言对应用开发者提供 ...

  8. iOS开发----地图与导航--定位和位置信息获取

    要实现地图.导航功能,往往需要先熟悉定位功能,在iOS中通过Core Location框架进行定位操作.Core Location自身可以单独使用,和地图开发框架MapKit完全是独立的,但是往往地图 ...

  9. iOS原生地图开发详解

    在上一篇博客中:http://my.oschina.net/u/2340880/blog/414760.对iOS中的定位服务进行了详细的介绍与参数说明,在开发中,地位服务往往与地图框架结合使用,这篇博 ...

随机推荐

  1. cesium js学习一加载三维模型【转】

    http://blog.csdn.net/tangyajun_168/article/details/50936698 最近项目中用到室外三维模型与室内三维地图交互,室外三维模型的加载我们采用了ces ...

  2. 关于html+ashx开发中几个问题的解决方法 (转)

    在跟html+ashx打交道的园友们肯定会发现,这种模式虽然优美,但在开发中会遇到一些难处理的地方.我也不例外,下面是自己在实际开发中总结出来的几条经验,希望跟大家分享,更希望得到大家的建议和更好的解 ...

  3. 用VS自带的打包程序打包Web程序,安装时安装中断

    出现这种问题,可能是你的IIS的兼容性问题: 把IIS兼容性安装好,再试试,应该可以了.

  4. js操作XML文件兼容IE与FireFox

    最近项目中用到了xml,需求是用户安装产品时先把一系列的数据保存到xml文件中,当执行到最后一步时才写入数据库,这样最大限度的减少了数据库的访问,于是不得不纠结在各浏览器的兼容性的问题(悲哀啊.... ...

  5. 【转】vim中多标签和多窗口的使用

    原文:https://my.oschina.net/kutengshe/blog/464602 ---------------------------------------------------- ...

  6. (转)最近一个项目中关于NGUI部分的总结(深度和drawCall)

    在自己最近的一个项目中,软件的界面部分使用了NGUI来进行制作.在制作过程中,遇到了一些问题,也获取了一些经验,总结下来,作为日后的积累. 1.NGUI图集的使用. 此次是第一个自己正儿八经的制作完整 ...

  7. Port already be taken

    我运行同一个docker run命令两次后,第二次给出提示,说端口已经被占用. Port has already been allocated [解决方法] 运行docker container ls ...

  8. CMake can't find GLEW

      Q: I'm on Windows and there is a FindGLEW.cmake file in my CMake modules folder, presumably put th ...

  9. mac 安装 RabbitMQ

    https://blog.csdn.net/u010046908/article/details/54773323

  10. editplus教程

    Editplus 3.0 开发ext 教程 使用Editplus配置轻型的PHP调试环境 Editplus已经使用了很多年,一直很喜欢这个小巧.精致的文本编辑器,比起ZenStudio这样庞大的IDE ...