高德地图关键字搜索oc版
.h文件
// MapSearchViewController.h
// JMT
//
// Created by walker on 16/10/11.
// Copyright © 2016年 BOOTCAMP. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AMapNaviKit/MaMapKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
typedef void(^moveBlock)(AMapPOI *location);
@interface MapSearchViewController : UIViewController
@property (nonatomic,retain) MAUserLocation *currentLocation;//当前位置
@property (nonatomic,retain) NSString *currentCity;//当前参数
@property (nonatomic,copy) moveBlock moveBlock;
@property (nonatomic,retain) NSString *searchStr;//搜索的内容
@property (nonatomic,strong) NSString *searchName;//点击cell时,cell的内容,利用代理传值,传回上一界面
@end
.m
//常量
#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
#import "MapSearchViewController.h"
#import <AMapSearchKit/AMapSearchKit.h>
//#import "MapViewController.h"
@interface MapSearchViewController ()<UISearchBarDelegate,UISearchResultsUpdating,UITableViewDataSource,UITableViewDelegate,AMapSearchDelegate,UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) UISearchController *searchController;
@property (nonatomic,retain) NSMutableArray *dataList;
@property (strong,nonatomic) NSMutableArray *searchList;
@property (nonatomic,retain) AMapSearchAPI *search;
@property (weak, nonatomic) IBOutlet UITextField *searchTextField;//搜索的文本输入框
@property (nonatomic,assign) BOOL isSelected;//是否点击了搜索,点击之前都是只能匹配
@end
@implementation MapSearchViewController
- (NSMutableArray *)searchList
{
if (!_searchList) {
_searchList = [NSMutableArray array];
}
return _searchList;
}
- (NSMutableArray *)dataList
{
if (!_dataList) {
_dataList = [NSMutableArray array];
}
return _dataList;
}
- (void)viewDidLoad {
[super viewDidLoad];
_search = [[AMapSearchAPI alloc] init];
_search.delegate = self;
//添加到顶部
_searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
_searchController.searchResultsUpdater = self;
_searchController.searchBar.delegate = self;
// _searchController.delegate = self;
_searchController.dimsBackgroundDuringPresentation = NO;
_searchController.hidesNavigationBarDuringPresentation = NO;
_searchController.searchBar.frame = CGRectMake(kWidth/2 - 100, 20, 200, 44.0);
self.navigationItem.titleView = self.searchController.searchBar;
self.searchController.searchBar.text = _searchStr;
[_searchController.searchBar becomeFirstResponder];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backToMapVC)];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CELL"];
_currentCity = @"河南省";
NSLog(@"搜索界面%@,%@",_currentLocation,_currentCity);
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[_searchController.searchBar becomeFirstResponder];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return _searchList.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//设置区域的行数(重点),这个就是使用委托之后需要需要判断是一下是否是需要使用Search之后的视图:
if (!_isSelected) {
return [self.searchList count];
}else{
return [self.dataList count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *flag=@"CELL";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:flag];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:flag];
}
//如果搜索框激活
if (!_isSelected) {
AMapPOI *poi = _searchList[indexPath.row];
[cell.textLabel setText:poi.name];
}
else{
AMapPOI *poi = _dataList[indexPath.row];
[cell.textLabel setText:poi.name];
}
return cell;
}
//点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.searchController.searchBar resignFirstResponder];
AMapPOI *poi = [[AMapPOI alloc]init];
//如果搜索框激活
if (!_isSelected) {
poi = _searchList[indexPath.row];
}
else{
poi = _dataList[indexPath.row];
}
NSLog(@"%@,%f,%f",poi.name,poi.location.latitude,poi.location.longitude);
_searchName = poi.name;
NSLog(@"_searchName%@",_searchName);
NSLog(@"poi.name%@",poi.name);
// self.moveBlock(poi);
//向上以页面传值并返回..
高德地图关键字搜索oc版相关推荐
- 利用高德地图关键字检索POI-实现仿微信发朋友圈搜索附近位置
转载请注明出处:http://blog.csdn.net/Alpha58/article/details/57079874 前言 由于项目中需要实现搜索附近位置作为收获地址,所以采用了高德地图的关键字 ...
- Android实现高德地图POI搜索
效果图如下: 导入高德地图的搜索服务包到工程的libs目录中,并配置好权限与用户KEY. 权限如下: <uses-permission android:name="android.pe ...
- Android反编译:手把手教你制作高德地图车机共存版
Android反编译:手把手教你制作高德地图车机共存版 前言 前期准备 反编译流程 反编译获取有效信息 修改关键信息 修改包名 修改其它配置 生成APK 重新打包成apk 重新签名 绕过校验机制 定位 ...
- 关于ArcGis for javascript整合百度地图 天地图 高德地图进行搜索
1.ArcGis for javascript整合百度地图搜索 1.1.首先引入百度地图的api 1 <!-- 引入百度地图API --> 2 <script type=" ...
- 高德地图关键字提示搜索获取经纬度
效果图: 具体代码: <!doctype html> <html> <head><meta charset="utf-8">< ...
- 高德地图怎么搜索marker_2018-07-06 高德地图搜索定位,滑动地图显示周边信息,根据地址搜经...
emmmm,效果图先行(搜索定位以及自由滑动地图展示周边位置信息,根据点击的位置获取经纬度) aa.gif 主要代码package com.dydd.wsp.dreamtree.ui.mapimpor ...
- vue中PC端使用高德地图 -- 实现搜索定位、地址标记、弹窗显示定位详情
PC端高德地图使用步骤: 1.注册并登录高德开放平台获取 2.安装高德依赖(amap-jsapi-loader) 3.初始化地图 4.首次打开地图获取当前定位并标记 5.根据已有地址自动定位到指定地址 ...
- 高德地图placesearch 搜索结果生成自定义marker
业务需求: 高德地图,输入关键词输入提示(autocomplete), 按照选择的关键词执行地点搜索placesearch在地图上生成标记点marker, 点击标记点弹出自定义信息窗口infowind ...
- android-4集成高德地图的搜索和导航功能
1.准备工作 1.1在高德地图导航包中用到的语音库为科大讯飞的,要使用的话也要在科大讯飞的开源平台上注册一个个人使用者key 1.2在使用高德地图的lib库时,最好使用导航和地图的合成库,如果导航库和 ...
最新文章
- linux系统创建lvm卷,LVM逻辑卷创建管理
- 经济学人:清华大学或将迅速成为全球科研领军者
- SaltStack状态导入(include)
- Flutter中关键字Const和Final之间的区别
- ERROR: Failed to find Platform SDK with path: platforms;android-27
- python基础常用语句-Python语言的一些基本常用语句
- EOS 智能合约源代码解读 (6)合约之action
- 深圳不完全启示录之初来乍到----1
- 微信“拍一拍”,竟然可以使用Python实现,你get到了吗?
- 基于JAVA+SpringMVC+MYSQL的在线招标管理系统
- 201403-1-相反数
- ie下的firebug
- Android中Bitmap、Drawable、byte[]转换
- Java面经总结(2020/10.20~11.20)
- 创新致胜,加速增长 | 世界人工智能大会RPA论坛重磅演讲嘉宾速览
- 福大研究生计算机学硕似录取,2017年福州大学数学与计算机学院专业型硕士研究生拟录取名单...
- 数据统计分析常用指标
- MADlib——基于SQL的数据挖掘解决方案(7)——数据转换之其它转换
- Ubuntu修改时区和更新时间
- Emacs 编辑环境,第1部分:学习Emacs的基础知识
热门文章
- 反汇编算法介绍和应用——线性扫描算法分析
- 【C++】多态问题:基类调用子类的protected或者private函数
- tensorflow 转张量类型为float_TensorFlow快速入门
- android应用去掉状态栏_Android 显示、隐藏状态栏和导航栏
- 判断小数是否相等_四年级上册数学填空+计算+判断易错题整理练习,收藏练一练!...
- scala定义抽象类与抽象字段
- linux7设置时间,CentOS 7 设置日期和时间
- 微信小程序 跑马灯效果完整代码附效果图
- liunx学习笔记(一:常用命令)
- Apache Tomcat 7.0.93 发布,开源 Java Web 应用服务器