参考文章  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. EF和LINQ 调用存储过程

    好久没有更新文章了,最近项目比较忙都没什么时间来分享最近的问题. 今天遇到一个超级傻逼的问题.C#中调用存储过程,自己code也10来年了,这应该是很简单的问题了.今天有2个新的api,一个只有1个参 ...

  2. 使用 AutoMapper 映射 IDataReader、DataSet、DataTable 到实体类

    AutoMapper是一个.NET的对象映射工具. 项目地址:https://github.com/AutoMapper/AutoMapper. 帮助文档:https://github.com/Aut ...

  3. js改变iframe 的src地址

    <script> function dizhi(){ document.getElementById("aaa").src='http://www.sohu.com' ...

  4. 利用blob对象实现粘贴图片

    blob的一个常用应用场景,就是获取剪切板上的数据来进行粘贴的操作.例如通过QQ截图后,需要在网页上进行粘贴操作. 粘贴图片我们需要解决下面几个问题 1.监听用户的粘贴操作 2.获取到剪切板上的数据 ...

  5. 转:PCA的Python实现

    http://blog.csdn.net/jerr__y/article/details/53188573 本文主要参考下面的文章,文中的代码基本是把第二篇文章的代码手写实现了一下. - pca讲解: ...

  6. 【转】TensorFlow四种Cross Entropy算法实现和应用

    http://www.jianshu.com/p/75f7e60dae95 作者:陈迪豪 来源:CSDNhttp://dataunion.org/26447.html 交叉熵介绍 交叉熵(Cross ...

  7. 未能加载文件或程序集“Microsoft.SqlServer.Sqm, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91”或它的某一个依赖项。系统找不到指定的文件。 (SqlMgmt)

    解决方法: Copy this file "Microsoft.SqlServer.Sqm.dll" in the forder "C:/Program Files/Mi ...

  8. [PureScript] Break up Expressions into Cases in PureScript using Simple Pattern Matching

    Pattern matching in functional programming languages is a way to break up expressions into individua ...

  9. php学习笔记之动态生成一组单选button

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. c++ 中const的使用

    在c++中.const是这么一个东西:假设你希望可以有一些东西是别人不能改动的,这个时候const就起作用了. const 在使用情况例如以下: a.修饰常量 const int a; int con ...