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中的定位服务进行了详细的介绍与参数说明,在开发中,地位服务往往与地图框架结合使用,这篇博 ...
随机推荐
- Learning to rank相关的pointwise,pairwise,listwise
论文分享--- >Learning to Rank: From Pairwise Approach to Listwise Approach 学习排序 Learning to Rank 小结 [ ...
- Java系列:使用软引用构建敏感数据的缓存
一.为什么需要使用软引用 首先,我们看一个雇员信息查询系统的实例.我们将使用一个Java语言实现的雇员信息查询系统查询存储在磁盘文件或者数据库中的雇员人事档案信息.作为一个用户,我们完全有可能需 ...
- centos6.8 mysql5.6.34 root密码重置
1.关闭正在运行的MySQL service mysql stop 2.启动MySQL的安全模式 mysqld_safe --skip-grant-tables 等1分钟如果还没返回的话,新开shel ...
- MFC中如何显示颜色选择对话框
其实很简单,使用MFC现有的类CColorDialog 即可实现 核心代码如下: void CCColorDialogView::OnGraphSetting() { CColorDialog m_s ...
- 转:ffmpeg time_base详解
ffmpeg time_base详解 https://my.oschina.net/u/3054677/blog/866368
- c# event Action 判断事件列表中是否存在这个委托
using UnityEngine; using System.Collections; using System; public class eventTest : MonoBehaviour { ...
- MySQL老是提示视图没有主键
写了一个视图,每次打开都提示没有主键.我又不想更新视图,根本不关心这个,但每次都提示,很烦. 网上找到解决办法,就是关闭提示: Windows 和 Linux:选择工具 > 选项,并在外观 &g ...
- jdbc:initialize-database标签的研究
在spring的applicationContext.xml中如果引入了:<?xml version="1.0" encoding="UTF-8"?> ...
- HTML DOM defaultValue 属性
定义和用法 defaultValue 属性设置或返回文本框的初始内容. 注释:文本框的初始值是位于 <textarea> 和 </textarea> 标签之间的文本.在表单被重 ...
- JERSEY中文翻译(第一章、Getting Started、2.2)
前言 这是jersey2.2的用户向导,我们会尽力维护它的更新并且也会增加新的章节.当阅读本用户指南的时候,也要参阅Jersey API 文档,额外的信息补充JERSEY的新特性和API 如果你想要为 ...