在进行iOS客户端开发的过程中,可能会用到高德地图的相关功能,下面我将对我所知道的功能进行描述。
发送当前地理位置
这时我推荐你使用SDK中的MAMapView,在这里如果你要添加标注图像,可以直接通过MAUserLocationRepresentation进行显示在当前位置。
如果你想更换为最近的位置,地图显示详见下边的 放大显示地图或手动选择地址,如果想要搜索最近的位置描述,推荐你分成两步:
一、使用AMapLocationManager获取当前地理位置
self.locationManager = [[AMapLocationManager alloc] init];
// 带逆地理信息的一次定位(返回坐标和地址信息)
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
// 定位超时时间,最低2s,此处设置为2s
self.locationManager.locationTimeout =2;
// 逆地理请求超时时间,最低2s,此处设置为2s
self.locationManager.reGeocodeTimeout = 2;
__weak typeof(self) ws = self;
[self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
if (error)
{
NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
if (error.code == AMapLocationErrorLocateFailed)
{
return;
}
return;
}
//经纬度为location.coordinate
}];
二、拿着获取到的经纬度进行搜索
ws.search = [[AMapSearchAPI alloc] init];
AMapPOIAroundSearchRequest *request=[[AMapPOIAroundSearchRequest alloc] init];
ws.search.delegate = self;
request.location=[AMapGeoPoint locationWithLatitude:location.coordinate.latitude
longitude:location.coordinate.longitude];
[ws.search AMapPOIAroundSearch:request];
然后通过下面的代理方法获取到搜索结果
-(void)onPOISearchDone:(AMapPOISearchBaseRequest *)request
response:(AMapPOISearchResponse *)response
cell显示地图
因为cell的重用性,不推荐使用原生的地图显示,所以这里推荐你使用高德地图的静态地图功能,具体描述可详见 https://lbs.amap.com/api/webservice/guide/api/staticmaps/
放大显示地图或手动选择地址
方法显示地图的时候一般属于浏览模式,需要指定坐标显示标注,如果手动选择地址的话,也需要通过坐标显示标注
那么对于需要指定坐标显示标注的时候,需要通过MAMapView显示地图,然后通过下面方式指定需要添加的标注位置:
CLLocationCoordinate2D location1;
location1.latitude = self.latitude;
location1.longitude = self.longitude;
self.mapView.centerCoordinate = location1;
然后通过如下的代理方法指定标注的相关信息
- (MAAnnotationView *)mapView:(MAMapView *)mapView
viewForAnnotation:(id<MAAnnotation>)annotation;
网友评论