定位 搜索 附近相關(guān)信息
- pod AMap2DMap
- pod AMapSeaerch
- pod AMapLocation
#import <MAMapKit/MAMapKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
#import <AMapLocationKit/AMapLocationKit.h>
@interface ViewController ()<MAMapViewDelegate,AMapSearchDelegate>
{
MAMapView * _mapView;
AMapSearchAPI * _search;
AMapLocationManager * _locationManager;
NSString * _position;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self searchPosition];
[self creatAmapView];
[self getCurrentPositionInfo];
}
#pragma mark -------------------根據(jù)經(jīng)緯度搜索周圍信息-------------------------
-(void)searchPosition{
//搜索地址獲得地址附近信息
[AMapSearchServices sharedServices].apiKey = @"你申請(qǐng)的key";
_search = [[AMapSearchAPI alloc] init];
_search.delegate = self;
[self ahah];
}
-(void)ahah{
AMapPOIAroundSearchRequest *request = [[AMapPOIAroundSearchRequest alloc] init];
request.location = [AMapGeoPoint locationWithLatitude:26.063184 longitude:119.298224];
request.keywords = _position;
// types屬性表示限定搜索POI的類別肃拜,默認(rèn)為:餐飲服務(wù)|商務(wù)住宅|生活服務(wù)
// POI的類型共分為20種大類別该园,分別為:
// 汽車服務(wù)|汽車銷售|汽車維修|摩托車服務(wù)|餐飲服務(wù)|購(gòu)物服務(wù)|生活服務(wù)|體育休閑服務(wù)|
// 醫(yī)療保健服務(wù)|住宿服務(wù)|風(fēng)景名勝|(zhì)商務(wù)住宅|政府機(jī)構(gòu)及社會(huì)團(tuán)體|科教文化服務(wù)|
// 交通設(shè)施服務(wù)|金融保險(xiǎn)服務(wù)|公司企業(yè)|道路附屬設(shè)施|地名地址信息|公共設(shè)施
request.types = @"餐飲服務(wù)|生活服務(wù)|商務(wù)住宅";
request.sortrule = 0;
request.radius = 700;
request.requireExtension = YES;
//發(fā)起周邊搜索
[_search AMapPOIAroundSearch: request];
}
//實(shí)現(xiàn)POI搜索對(duì)應(yīng)的回調(diào)函數(shù)
- (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response
{
if(response.pois.count == 0)
{
return;
}
//通過 AMapPOISearchResponse 對(duì)象處理搜索結(jié)果
//NSString *strCount = [NSString stringWithFormat:@"count: %ld",response.count];
//NSString *strSuggestion = [NSString stringWithFormat:@"Suggestion: %@", response.suggestion];
NSString *strPoi = @"";
for (AMapPOI *p in response.pois) {
strPoi = [NSString stringWithFormat:@"%@\nPOI: %@", strPoi, p.description];
NSLog(@"%@*%@*%@",p.description,p.name,p.address);
}
}
#pragma mark ------------------------地圖的創(chuàng)建---------------------------
-(void)creatAmapView{
//地圖
[MAMapServices sharedServices].apiKey = @"你申請(qǐng)的key";
_mapView = [[MAMapView alloc] initWithFrame:self.view.frame];
_mapView.showsUserLocation = YES;
[_mapView setZoomLevel:16.1 animated:YES];
_mapView.delegate = self;
_mapView.userTrackingMode = MAUserTrackingModeFollow;
[self.view addSubview:_mapView];
}
-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation
updatingLocation:(BOOL)updatingLocation
{
if(updatingLocation)
{
//取出當(dāng)前位置的坐標(biāo)
//NSLog(@"latitude : %f,longitude: %f",userLocation.coordinate.latitude,userLocation.coordinate.longitude);
}
}
#pragma mark -----------------獲得當(dāng)前位置信息城市 區(qū) 街道-------------------------
-(void)getCurrentPositionInfo{
[AMapLocationServices sharedServices].apiKey = @"你申請(qǐng)的key";
_locationManager = [[AMapLocationManager alloc] init];
[_locationManager setDistanceFilter:kCLLocationAccuracyKilometer];
[self getCurrentAddress];
}
//獲取當(dāng)前位置信息
-(void)getCurrentAddress{
[_locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
if (error) {
NSLog(@"獲取當(dāng)前地址錯(cuò)誤");
return;
}
NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
[addressDic setValue:regeocode.province forKey:@"province"];
// [addressDic setValue:regeocode.city forKey:@"city"];
// [addressDic setValue:regeocode.district forKey:@"district"];
NSString * position = [NSString stringWithFormat:@"%@%@%@%@",regeocode.city,regeocode.district,regeocode.street,regeocode.number];
_position = position;
//city 市 district 區(qū) street 街道 number 街道號(hào)碼
NSLog(@"%@%@%@%@",regeocode.city,regeocode.district,regeocode.street,regeocode.number);
}];
}
#pragma mark --------點(diǎn)擊地圖得到點(diǎn)擊點(diǎn)的坐標(biāo)------------------
//點(diǎn)擊地圖獲得該點(diǎn)擊地點(diǎn)的經(jīng)緯度
-(void)mapView:(MAMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate{
NSLog(@"%f,%f",coordinate.latitude,coordinate.longitude);
}```
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者