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中的定位服务进行了详细的介绍与参数说明,在开发中,地位服务往往与地图框架结合使用,这篇博 ...
随机推荐
- C# 二种方法控制系统音量/麦克风大小
场景:在做播放设备的时候需要控制音量的大小,下面几种方法将满足你的要求 方法一: 改变系统音量设置 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
- Git 以分支的方式同时管理多个项目
你是否遇到过这样的问题: 你的客户在你们这边做了N个项目,而项目之间又存在着某些业务关联(数据库访问等) 之前你可能是这样处理的,为客户的每个项目创建单独的Git版本 PC项目 手机项目 微信项目 其 ...
- VS2013开发asmx接口返回一个自定义XML
1:利用XmlDocument生成一个xml文档返回,代码如下 using System;using System.Collections.Generic;using System.Linq;usin ...
- Log4net PatternLayout 参数
Log4net PatternLayout 参数 来自: https://logging.apache.org/log4net/log4net-1.2.13/release/sdk/log4net.L ...
- windows server 2012 st 版本的php环境问题修复 与删除
windows server 2012 st 版本的php环境问题修复 错误内容 HTTP 错误 500.0 - Internal Server Error C:\Program Files\iis ...
- 2012年5月阿里巴巴集团”去 IOE”运动的思考与总结【转载+整理】
原文地址 什么是 IOE,IOE 只是一个简称,分别代表 IBM.Oracle.EMC,确切地说是 IBM 小型机.Oracle 数据库与 EMC 存储设备的组合.这"三驾马车"构 ...
- ext js/Ext.Net_演示 htmleditor 上传&插入图片
本文内容 解决方案结构 HtmlEditor_Upload.js 脚本 HtmlEditorUploadImg.ashx 上传图片到服务器 演示 htmleditor 控件添加插入图片功能 解决方 ...
- mybatis学习资源
官网:http://mybatis.org/index.html 代码:https://code.google.com/p/mybatisnet/ wiki:http://zh.wikipedia.o ...
- iOS 真机上图标不显示
今天在调试时发现模拟器上图标显示了.但真机上测试时发现图标不显示. 解决办法 57*57 的图标然后命名为: Icon.png 这样显示就正常了. 参考资料:http://www.cnblogs.c ...
- Python 函数参数引用(传值/传址)/copy/deepcopy
精简版: 传值:被调函数局部变量改变不会影响主调函数局部变量 传址:被调函数局部变量改变会影响主调函数局部变量 Python参数传递方式:传递对象引用(传值和传址的混合方式),如果是数字,字符串,元组 ...