CoreLocation.framework框架基本用法
来源:互联网 发布:杭州淘宝代运营收费 编辑:程序博客网 时间:2024/04/29 15:43
//// ViewController.m// Search//// Created by lcy on 16/1/14.// Copyright (c) 2016年 lcy. All rights reserved.//#import "ViewController.h"#import <MapKit/MapKit.h>#import "CYAnnotationView.h"@interface ViewController () <UISearchBarDelegate,MKMapViewDelegate>@property (nonatomic,strong) MKMapView *mapView;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 375, 44)]; searchBar.delegate = self; searchBar.showsCancelButton = YES; self.navigationItem.titleView = searchBar; self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; self.mapView.delegate = self; [self.mapView setRegion:MKCoordinateRegionMake(CLLocationCoordinate2DMake(22.533367, 113.935404), MKCoordinateSpanMake(0.1, 0.1)) animated:YES]; [self.view addSubview:self.mapView]; UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; [self.mapView addGestureRecognizer:longPress];}-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{ //判断 如果是自己的大头针 才会自定义 否则 直接返回系统默认的大头针 if([annotation isKindOfClass:[MKPointAnnotation class]]) { //重用队列中 取大头针 MKAnnotationView *view = [mapView dequeueReusableAnnotationViewWithIdentifier:@"cell"]; //如果不存在 创建大头针 if(view == nil) { view = [[CYAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"cell"]; } #if 0 //得到对应的类型的view 改变大头针的颜色 MKPinAnnotationView *pinView = (MKPinAnnotationView *)view; pinView.pinColor = MKPinAnnotationColorGreen; pinView.animatesDrop = YES;#endif return view; } return nil;}-(void)longPress:(UILongPressGestureRecognizer *)press{ if(press.state == UIGestureRecognizerStateBegan) { CGPoint point = [press locationInView:self.mapView]; CLLocationCoordinate2D coor = [self.mapView convertPoint:point toCoordinateFromView:self.view]; MKPointAnnotation *ann = [[MKPointAnnotation alloc] init]; ann.title = @"新的大头针"; ann.coordinate = coor; [self.mapView addAnnotation:ann]; }}-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{ [searchBar resignFirstResponder];}-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ [searchBar resignFirstResponder]; MKLocalSearchRequest *req = [[MKLocalSearchRequest alloc] init]; //seaxx.text //搜索内容 req.naturalLanguageQuery = searchBar.text; //搜索范围 req.region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(22.533367, 113.935404), MKCoordinateSpanMake(0.1, 0.1)); MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:req]; [search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) { //删除之前的大头针 [self.mapView removeAnnotations:self.mapView.annotations]; for (MKMapItem *item in response.mapItems) { NSLog(@"%@",item.name); NSLog(@"%@",item.phoneNumber); //大头针 MKPointAnnotation *pointAnn = [[MKPointAnnotation alloc] init]; pointAnn.title = item.name; pointAnn.subtitle = item.phoneNumber; //位置 pointAnn.coordinate = item.placemark.location.coordinate; [self.mapView addAnnotation:pointAnn]; } }];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- CoreLocation.framework框架基本用法
- CoreLocation.framework
- CoreLocation 用法
- ios私有框架MobileWiFi.framework的基本用法
- CoreLocation框架的基本使用—区域监听
- CoreText.framework --- 基本用法
- Entity Framework 基本用法
- Entity Framework 基本用法
- CoreLocation的基本使用
- CoreLocation基本使用
- 附图1:Framework基本框架
- CoreLocation框架的使用
- CoreLocation框架的使用
- CoreLocation框架定位详解
- iOS CoreLocation框架 定位
- CoreLocation框架的使用
- iOS开发CoreLocation框架
- IOS CoreText.framework --- 基本用法
- 【android】ArrayAdapter 使用浅析
- 分享几个图标素材网址
- Linux查看JDK的安装路径和JAVA_HOME的环境变量设置
- ZOJ-3923-In the Rain
- Win7 自带IIS7局域网无法访问解决办法
- CoreLocation.framework框架基本用法
- pat1016:部分A+B
- 杭电1217
- [C语言][LeetCode][83]Remove Duplicates from Sorted List
- 深入理解SetUID
- c++primer(第五版) 第十二章 动态内存习题答案
- Maximal Information Coefficient 最大信息系数
- 在终端上访问网站和下载文件
- pat1017:A除以B