获取POI数据

您所在的位置:网站首页 高德地图数据采集器下载 获取POI数据

获取POI数据

2023-07-06 06:46| 来源: 网络整理| 查看: 265

高德提供了千万级别的POI(Point of Interest,兴趣点)。在地图表达中,一个POI可代表一栋大厦、一家商铺、一处景点等等。通过POI搜索,完成找餐馆、找景点、找厕所等等的功能。

注意:下面介绍的功能使用的是地图SDK的搜索功能,需要在工程中导入搜索功能库(AMapSearchKit.framework)。

根据关键字检索POI关键字检索介绍

根据关键字检索适用于在某个城市搜索某个名称相关的POI,例如:查找北京市的“肯德基”。

注意:

1、关键字未设置城市信息(默认为全国搜索)时,如果涉及多个城市数据返回,仅会返回建议城市,请根据APP需求,选取城市进行搜索。

2、不设置POI的类别,默认返回“餐饮服务”、“商务住宅”、“生活服务”这三种类别的POI,下方提供了POI分类码表,请按照列表内容设置希望检索的POI类型。(建议使用POI类型的代码进行检索)

使用关键字检索第 1 步,引入头文件

引入 AMapFoundationKit.h 和 AMapSearchKit.h 这两个头文件。

Objective-CSwift#import #import //在桥接文件中引入头文件 #import #import 第 2 步,配置Key

在使用搜索功能时,需要添加 Key。

如果您使用的是搜索库(AMapSearchKit.framework) v4.x 版本需要引入基础 SDK AMapFoundationKit.framework ,设置 Key 的方法如下:

iOS 搜索功能 v4.x 版本设置 Key:

Objective-CSwift[AMapServices sharedServices].apiKey = @"您的key"; AMapServices.shared().apiKey = "您的Key"

如果您使用的是搜索功能 v3.x 或之前版本,请您尽快更新。

iOS 搜索功能 v3.x 版本设置 Key:

Objective-CSwift[AMapSearchServices sharedServices].apiKey = @"您的key"; AMapSearchServices.shared().apiKey = "您的Key"第 3 步,定义 AMapSearchAPI

定义主搜索对象 AMapSearchAPI ,并继承搜索协议。

第 4 步,构造 AMapSearchAPI

构造主搜索对象 AMapSearchAPI,并设置代理。

Objective-CSwiftself.search = [[AMapSearchAPI alloc] init]; self.search.delegate = self; search = AMapSearchAPI() search.delegate = self第 5 步,设置关键字检索参数

进行关键字检索的请求参数类为 AMapPOIKeywordsSearchRequest,其中 keywords 是必设参数。types 为搜索类型。

Objective-CSwiftAMapPOIKeywordsSearchRequest *request = [[AMapPOIKeywordsSearchRequest alloc] init]; request.keywords = @"北京大学"; request.city = @"北京"; request.types = @"高等院校"; request.requireExtension = YES; /* 搜索SDK 3.2.0 中新增加的功能,只搜索本城市的POI。*/ request.cityLimit = YES; request.requireSubPOIs = YES; let request = AMapPOIKeywordsSearchRequest() request.keywords = keyword request.requireExtension = true request.city = "北京" request.cityLimit = true request.requireSubPOIs = true第 6 步,发起POI关键字搜索

调用 AMapSearchAPI 的 AMapPOIKeywordsSearch 并发起关键字检索。

Objective-CSwift[self.search AMapPOIKeywordsSearch:request]; search.aMapPOIKeywordsSearch(request)第 7 步,在回调中处理数据

当检索成功时,会进到 onPOISearchDone 回调函数中,通过解析 AMapPOISearchResponse 对象把检索结果在地图上绘制点展示出来。

说明:

1)可以在回调中解析 response,获取 POI 信息。

2)response.pois 可以获取到 AMapPOI 列表,POI 详细信息可参考 AMapPOI 类。

3)若当前城市查询不到所需 POI 信息,可以通过 response.suggestion.cities 获取当前 POI 搜索的建议城市。

4)如果搜索关键字明显为误输入,则可通过 response.suggestion.keywords 属性得到搜索关键词建议。

Objective-CSwift/* POI 搜索回调. */ - (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response { if (response.pois.count == 0) { return; } //解析response获取POI信息,具体解析见 Demo } func onPOISearchDone(_ request: AMapPOISearchBaseRequest!, response: AMapPOISearchResponse!) { if response.count == 0 { return } //解析response获取POI信息,具体解析见 Demo }

点我下载POI分类码表

检索周边POI周边检索介绍

适用于搜索某个位置附近的POI,可设置POI的类别,具体查询所在位置的餐饮类、住宅类POI,例如:查找天安门附近的厕所等等场景。

说明:

1、支持指定查询POI的类别。高德地图的POI类别共20个大类,分别为:汽车服务、汽车销售、汽车维修、摩托车服务、餐饮服务、购物服务、生活服务、体育休闲服务、医疗保健服务、住宿服务、风景名胜、商务住宅、政府机构及社会团体、科教文化服务、交通设施服务、金融保险服务、公司企业、道路附属设施、地名地址信息、公共设施,同时,每个大类别都还有二级以及三级的细小划分,具体的POI类别请参考:POI分类编码表。

2、不设置POI的类别,默认返回“餐饮服务”、“商务住宅”、“生活服务”这三种类别的POI。

使用周边检索第 1 步,引入头文件

引入 AMapFoundationKit.h 和 AMapSearchKit.h 这两个头文件。

Objective-CSwift#import #import //在桥接文件中引入头文件 #import #import 第 2 步,配置Key

在使用搜索功能时,需要添加 Key。

如果您使用的是搜索库(AMapSearchKit.framework) v4.x 版本需要引入基础 SDK AMapFoundationKit.framework ,设置 Key 的方法如下:

iOS 搜索功能 v4.x 版本设置 Key:

Objective-CSwift[AMapServices sharedServices].apiKey = @"您的key"; AMapServices.shared().apiKey = "您的Key"

如果您使用的是搜索功能 v3.x 或之前版本,请您尽快更新。

iOS 搜索功能 v3.x 版本设置 Key:

Objective-CSwift[AMapSearchServices sharedServices].apiKey = @"您的key"; AMapSearchServices.shared().apiKey = "您的Key"第 3 步,定义 AMapSearchAPI

定义主搜索对象 AMapSearchAPI ,并继承搜索协议。

第 4 步,构造 AMapSearchAPI

构造主搜索对象 AMapSearchAPI,并设置代理。

Objective-CSwiftself.search = [[AMapSearchAPI alloc] init]; self.search.delegate = self; search = AMapSearchAPI() search.delegate = self第 5 步,设置周边检索的参数

请求参数类为 AMapPOIAroundSearchRequest,location是必设参数。

Objective-CSwiftAMapPOIAroundSearchRequest *request = [[AMapPOIAroundSearchRequest alloc] init]; request.location = [AMapGeoPoint locationWithLatitude:39.990459 longitude:116.481476]; request.keywords = @"电影院"; /* 按照距离排序. */ request.sortrule = 0; request.requireExtension = YES; let request = AMapPOIAroundSearchRequest() request.tableID = TableID request.location = AMapGeoPoint.location(withLatitude: CGFloat(39.990459), longitude: CGFloat(116.481476)) request.keywords = "电影院" request.requireExtension = true第 6 步,发起周边检索

调用 AMapSearchAPI 的 AMapPOIAroundSearch 并发起周边检索。

Objective-CSwift[self.search AMapPOIAroundSearch:request]; search.aMapPOIAroundSearch(request)第 7 步,在回调中处理数据

当检索成功时,会进到 onPOISearchDone 回调函数中,通过解析 AMapPOISearchResponse 对象把检索结果在地图上绘制点展示出来。

说明:

1)可以在回调中解析 response,获取 POI 信息。

2)response.pois 可以获取到 AMapPOI 列表,POI 详细信息可参考 AMapPOI 类。

3)若当前城市查询不到所需 POI 信息,可以通过 response.suggestion.cities 获取当前 POI 搜索的建议城市。

4)如果搜索关键字明显为误输入,则可通过 response.suggestion.keywords法得到搜索关键词建议。

Objective-CSwift/* POI 搜索回调. */ - (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response { if (response.pois.count == 0) { return; } //解析response获取POI信息,具体解析见 Demo } func onPOISearchDone(_ request: AMapPOISearchBaseRequest!, response: AMapPOISearchResponse!) { if response.count == 0 { return } //解析response获取POI信息,具体解析见 Demo }检索多边形内的POI多边形检索介绍

不同于周边搜索,周边搜索是一个圆形范围,而多边形搜索的范围是一个多边形,适用于在搜索某个不规则区域的POI,例如:查找中关村范围内的停车场。

使用多边形检索第 1 步,引入头文件

引入 AMapFoundationKit.h 和 AMapSearchKit.h 这两个头文件。

Objective-CSwift#import #import //在桥接文件中引入头文件 #import #import 第 2 步,配置Key

在使用搜索功能时,需要添加 Key。

如果您使用的是搜索库(AMapSearchKit.framework) v4.x 版本需要引入基础 SDK AMapFoundationKit.framework ,设置 Key 的方法如下:

iOS 搜索功能 v4.x 版本设置 Key:

Objective-CSwift[AMapServices sharedServices].apiKey = @"您的key"; AMapServices.shared().apiKey = "您的Key"

如果您使用的是搜索功能 v3.x 或之前版本,请您尽快更新。

iOS 搜索功能 v3.x 版本设置 Key:

Objective-CSwift[AMapSearchSearchServices sharedServices].apiKey = @"您的key"; AMapServices.shared().apiKey = "您的Key"第 3 步,定义 AMapSearchAPI

定义主搜索对象 AMapSearchAPI ,并继承搜索协议。

第 4 步,构造 AMapSearchAPI

构造主搜索对象 AMapSearchAPI,并设置代理。

Objective-CSwiftself.search = [[AMapSearchAPI alloc] init]; self.search.delegate = self; search = AMapSearchAPI() search.delegate = self第 5 步,设置多边形检索的参数

请求参数类为 AMapPOIPolygonSearchRequest,polygon是必填参数。

Objective-CSwiftNSArray *points = [NSArray arrayWithObjects: [AMapGeoPoint locationWithLatitude:39.990459 longitude:116.481476], [AMapGeoPoint locationWithLatitude:39.890459 longitude:116.581476], nil]; AMapGeoPolygon *polygon = [AMapGeoPolygon polygonWithPoints:points]; AMapPOIPolygonSearchRequest *request = [[AMapPOIPolygonSearchRequest alloc] init]; request.polygon = polygon; request.keywords = @"Apple"; request.requireExtension = YES; let request = AMapPOIPolygonSearchRequest() let points: [AMapGeoPoint] = [AMapGeoPoint.location(withLatitude: CGFloat(39.990459), longitude: CGFloat(116.481476)), AMapGeoPoint.location(withLatitude: CGFloat(39.890459), longitude: CGFloat(116.581476))] request.polygon = AMapGeoPolygon.init(points: points) request.keywords = "Apple" request.requireExtension = true第 6 步,发起多边形检索

调用 AMapSearchAPI 的 AMapPOIPolygonSearch 并发起多边形检索。

Objective-CSwift[self.search AMapPOIPolygonSearch:request]; search.aMapPOIPolygonSearch(request)第 7 步,在回调中处理数据

当检索成功时,会进到 onPOISearchDone 回调函数中,通过解析 AMapPOISearchResponse 对象把检索结果在地图上绘制点展示出来。

说明:

1)可以在回调中解析 response,获取 POI 信息。

2)response.pois 可以获取到 AMapPOI 列表,POI 详细信息可参考 AMapPOI 类。

3)若当前城市查询不到所需 POI 信息,可以通过 response.suggestion.cities 获取当前 POI 搜索的建议城市。

4)如果搜索关键字明显为误输入,则可通过 response.suggestion.keywords法得到搜索关键词建议。

Objective-CSwift/* POI 搜索回调. */ - (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response { if (response.pois.count == 0) { return; } //解析response获取POI信息,具体解析见 Demo } func onPOISearchDone(_ request: AMapPOISearchBaseRequest!, response: AMapPOISearchResponse!) { if response.count == 0 { return } //解析response获取POI信息,具体解析见 Demo }根据ID检索POIID检索介绍

通过关键字检索、周边检索以及多边形检索查询到的POI信息,可通过ID检索来获取POI详细的信息。

使用ID检索第 1 步,引入头文件

引入 AMapFoundationKit.h 和 AMapSearchKit.h 这两个头文件。

Objective-CSwift#import #import //在桥接文件中引入头文件 #import #import 第 2 步,配置Key

在使用搜索功能时,需要添加 Key。

如果您使用的是搜索库(AMapSearchKit.framework) v4.x 版本需要引入基础 SDK AMapFoundationKit.framework ,设置 Key 的方法如下:

iOS 搜索功能 v4.x 版本设置 Key:

Objective-CSwift[AMapServices sharedServices].apiKey = @"您的key"; AMapServices.shared().apiKey = "您的Key"

如果您使用的是搜索功能 v3.x 或之前版本,请您尽快更新。

iOS 搜索功能 v3.x 版本设置 Key:

Objective-CSwift[AMapSearchServices sharedServices].apiKey =@"您的key"; AMapSearchServices.shared().apiKey = "您的Key"第 3 步,定义 AMapSearchAPI

定义主搜索对象 AMapSearchAPI ,并继承搜索协议。

第 4 步,构造 AMapSearchAPI

构造主搜索对象 AMapSearchAPI,并设置代理。

Objective-CSwiftself.search = [[AMapSearchAPI alloc] init]; self.search.delegate = self; search = AMapSearchAPI() search.delegate = self第 5 步,设置ID检索的参数Objective-CSwiftAMapPOIIDSearchRequest *request = [[AMapPOIIDSearchRequest alloc] init]; request.uid = poiId; request.requireExtension = YES; let request = AMapPOIIDSearchRequest() request.uid = poiId request.requireExtension = true第 6 步,发起ID检索Objective-CSwift[self.search AMapPOIIDSearch:request]; search.aMapPOIIDSearch(request)第 7 步,在回调中处理数据

当检索成功时,会进到 onPOISearchDone 回调函数中,通过解析 AMapPOISearchResponse 对象把检索结果在地图上绘制点展示出来。

说明:

1)可以在回调中解析 response,获取 POI 信息。

2)response.pois 可以获取到 AMapPOI 列表,POI 详细信息可参考 AMapPOI 类。

3)若当前城市查询不到所需 POI 信息,可以通过 response.suggestion.cities 获取当前 POI 搜索的建议城市。

4)如果搜索关键字明显为误输入,则可通过 response.suggestion.keywords法得到搜索关键词建议。

Objective-CSwift/* POI 搜索回调. */ - (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response { if (response.pois.count == 0) { return; } //解析response获取POI信息,具体解析见 Demo } func onPOISearchDone(_ request: AMapPOISearchBaseRequest!, response: AMapPOISearchResponse!) { if response.count == 0 { return } //解析response获取POI信息,具体解析见 Demo }获取道路沿途的POI

从搜索 SDK 4.3.0 版本开始支持,可根据规划的路径,查询该路径沿途的加油站、ATM、汽修店、厕所。

第 1 步,引入头文件

引入 AMapFoundationKit.h 和 AMapSearchKit.h 这两个头文件。

Objective-CSwift#import #import //在桥接文件中引入头文件 #import #import 第 2 步,配置Key

在使用搜索功能时,需要添加 Key。

如果您使用的是搜索库(AMapSearchKit.framework) v4.x 版本需要引入基础 SDK AMapFoundationKit.framework ,设置 Key 的方法如下:

iOS 搜索功能 v4.x 版本设置 Key:

Objective-CSwift[AMapServices sharedServices].apiKey = @"您的key"; AMapServices.shared().apiKey = "您的Key"

如果您使用的是搜索功能 v3.x 或之前版本,请您尽快更新。

iOS 搜索功能 v3.x 版本设置 Key:

Objective-CSwift[AMapSearchServices sharedServices].apiKey =@"您的key"; AMapSearchServices.shared().apiKey = "您的Key"第 3 步,定义 AMapSearchAPI

定义主搜索对象 AMapSearchAPI ,并继承搜索协议。

第 4 步,构造 AMapSearchAPI

构造主搜索对象 AMapSearchAPI,并设置代理。

Objective-CSwiftself.search = [[AMapSearchAPI alloc] init]; self.search.delegate = self; search = AMapSearchAPI() search.delegate = self第 5 步,设置沿途搜索的参数

请求参数类为  AMapRoutePOISearchRequest ,origin和destination是必填参数。

Objective-CAMapRoutePOISearchRequest *request = [[AMapRoutePOISearchRequest alloc] init]; request.origin = [AMapGeoPoint locationWithLatitude:self.startCoordinate.latitude longitude:self.startCoordinate.longitude]; request.destination = [AMapGeoPoint locationWithLatitude:self.destinationCoordinate.latitude longitude:self.destinationCoordinate.longitude]; request.strategy = self.strategy; request.searchType = self.segmentControl.selectedSegmentIndex; 第 6 步,发起沿途搜索Objective-C[self.search AMapRoutePOISearch:request]; 第 7 步,在回调中处理数据

当检索成功时,会进到 onRoutePOISearchDone 回调函数中,通过解析 AMapRoutePOISearchResponse 对象获取POI,并在地图上显示。

说明:

1)可以在回调中解析 response,获取 POI 信息。

2)response.pois 可以获取到 AMapPOI 列表,POI 详细信息可参考 AMapPOI 类。

Objective-C/* 沿途搜索回调. */ - (void)onRoutePOISearchDone:(AMapRoutePOISearchRequest *)request response:(AMapRoutePOISearchResponse *)response { if (response.pois.count == 0) { return; } //解析response获取POI信息,具体解析见 Demo } 根据输入给出提示语输入提示查询介绍

输入提示是指根据用户输入的关键词,给出相应的提示信息,将最有可能的搜索词呈现给用户,以减少用户输入信息,提升用户体验。如:输入“方恒”,提示“方恒国际中心A座”,“方恒购物中心”等。

输入提示返回的提示语对象 AMapTip 有多种属性,可根据该对象的返回信息,配合其他搜索服务使用,完善您应用的功能。如:

1)uid为空,location为空,该提示语为品牌词,可根据该品牌词进行POI关键词搜索。

2)uid不为空,location为空,为公交线路,根据uid进行公交线路查询。

3)uid不为空,location也不为空,是一个真实存在的POI,可直接显示在地图上。

使用输入提示查询第 1 步,引入头文件

引入 AMapFoundationKit.h 和 AMapSearchKit.h 这两个头文件。

Objective-CSwift#import #import //在桥接文件中引入头文件 #import #import 第 2 步,配置Key

在使用搜索功能时,需要添加 Key。

如果您使用的是搜索库(AMapSearchKit.framework) v4.x 版本需要引入基础 SDK AMapFoundationKit.framework ,设置 Key 的方法如下:

iOS 搜索功能 v4.x 版本设置 Key:

Objective-CSwift[AMapServices sharedServices].apiKey = @"您的key"; AMapServices.shared().apiKey = "您的Key"

如果您使用的是搜索功能 v3.x 或之前版本,请您尽快更新。

iOS 搜索功能 v3.x 版本设置 Key:

Objective-CSwift[AMapSearchServices sharedServices].apiKey =@"您的key"; AMapSearchServices.shared().apiKey = "您的Key"第 3 步,定义 AMapSearchAPI

定义主搜索对象 AMapSearchAPI ,并继承搜索协议。

第 4 步,构造 AMapSearchAPI

构造主搜索对象 AMapSearchAPI,并设置代理。

Objective-CSwiftself.search = [[AMapSearchAPI alloc] init]; self.search.delegate = self; search = AMapSearchAPI() search.delegate = self第 5 步,设置输入提示查询的参数

请求参数类为 AMapInputTipsSearchRequest,keywords是必填参数。

Objective-CSwiftAMapInputTipsSearchRequest *tips = [[AMapInputTipsSearchRequest alloc] init]; tips.keywords = key; tips.city = @"北京"; // tips.cityLimit = YES; 是否限制城市 let request = AMapInputTipsSearchRequest() request.keywords = keyword request.city = "北京" // request.cityLimit = true第 6 步,发起输入提示语查询Objective-CSwift[self.search AMapInputTipsSearch:tips]; search.aMapInputTipsSearch(request)第 7 步,在回调中处理数据

当检索成功时,会进到 onInputTipsSearchDone 回调函数中,通过解析 AMapInputTipsSearchResponse 对象获取输入提示词进行展示。

说明:

1)可以在回调中解析 response,获取提示词。

2)通过 response.tips 可以获取到 AMapTip 列表,Poi详细信息可参考 AMapTip 类(包含:adcode、district、name等信息)。

Objective-CSwift/* 输入提示回调. */ - (void)onInputTipsSearchDone:(AMapInputTipsSearchRequest *)request response:(AMapInputTipsSearchResponse *)response { //解析response获取提示词,具体解析见 Demo } func onInputTipsSearchDone(_ request: AMapInputTipsSearchRequest!, response: AMapInputTipsSearchResponse!) { if response.count == 0 { return } //解析response获取提示词,具体解析见 Demo }说明

当检索失败时,会进入 didFailWithError 回调函数,通过该回调函数获取产生的失败的原因。

Objective-CSwift- (void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error { NSLog(@"Error: %@", error); } func aMapSearchRequest(_ request: Any!, didFailWithError error: Error!) { print("Error:\(error)") }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3