目錄
一. 定位功能
iPhone手機定位(基站定位, WiFi定位, GPS定位: 定位所需時間遞增, 精確度遞增)
- 導(dǎo)入CoreLocation庫
- 創(chuàng)建CLLocationManager對象
- 設(shè)置更新位置的周期(距離)
- 設(shè)置定位的精度
- 開始定位
- iOS8中要在Info.plist添加一組鍵值對, 并執(zhí)行
- (void)requestWhenInUseAuthorization
方法- 遵守協(xié)議
<CLLocationManagerDelegate>
后可以獲取更新位置
二. 系統(tǒng)地圖
- 導(dǎo)入MapKit庫
- 創(chuàng)建地圖對象, 設(shè)置地圖類型, 地圖區(qū)域(region包含中心點和半徑), 顯示視圖
- 定位當前位置(除了CLLocationManager對象外, 要設(shè)置顯示位置
_mapView.showsUserLocation = YES
)- 在CLLocationManager的代理方法中, 設(shè)置將地圖位置設(shè)置地圖的中心點
[_mapView setCenterCoordinate:loc.coordinate animated:YES]
三. 系統(tǒng)地圖的大頭針
- 設(shè)置地圖對象
- 設(shè)置大頭針(一般通過手勢點擊來添加大頭針MKPointAnnotation: 需要設(shè)置其經(jīng)緯度, 酌情設(shè)置大小標題和左右視圖)
- 顯示大頭針: 設(shè)置地圖對象的代理, 遵守MKMapViewDelegate協(xié)議
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
- 想要通過點擊大頭針的Callout視圖中的UIControl對象調(diào)用方法的話, 需要遵守
MKMapViewDelegate
協(xié)議實現(xiàn)代理方法- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
- 注意點: 如果想創(chuàng)建靜態(tài)圖片作為大頭針圖片的話山上,可以創(chuàng)建MKAnnotationView實例;如果想使用apple自帶的大頭針則創(chuàng)建MKPinAnnotationView
If the annotation can be represented by a static image, create an instance of the MKAnnotationView class and assign the image to its image property; see “Using the Standard Annotation Views.”
If you want to use a standard pin annotation, create an instance of the MKPinAnnotationView class; see “Using the Standard Annotation Views.”
四. 自定義大頭針
- 自定義大頭針類MyAnnotation(需要遵守MKAnnotation協(xié)議, 需要自己設(shè)標題, 副標題, 經(jīng)緯度; 不需要設(shè)置左右兩個視圖)
- 顯示mapView, 在mapView上添加長按手勢以添加自定義Annotation, 在代理方法中- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation中顯示Annotation(可以設(shè)置Annotation的圖片, 添加左右CalloutAccessoryView)
- 之后就可以通過一些設(shè)置來彈出視圖, 傳參......
五. 地址解析和反地址解析
六. 高德地圖
- 前期準備: 按照官網(wǎng)教程
- 顯示地圖, 搜索地點, 地址解碼和反解碼的示例代碼
一. 定位功能
1. 導(dǎo)入CoreLocation的頭文件, 設(shè)置定位管理對象為成員變量
{
// 定位管理對象
CLLocationManager *_manager;
}
2. 設(shè)置定位管理對象
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// iOS8之前做到5步就可以
// 1. 創(chuàng)建定位管理對象
_manager = [[CLLocationManager alloc] init];
// 2. 表示手機移動50米才更新定位的位置
_manager.distanceFilter = 50;
// 3. 表示定位的精度
_manager.distanceFilter = kCLLocationAccuracyBest;
// 4. 設(shè)置代理
_manager.delegate = self;
// 5. 開始定位
[_manager startUpdatingLocation];
// 6. 獲取手機的方向, 去對應(yīng)代理方法中獲取
// [_manager startUpdatingHeading];
// iOS8需要設(shè)置Info.plist文件里面的值
// NSLocationWhenInUseUsageDescription == YES
// NSLocationAlwaysUsageDescription == YES
if ([_manager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[_manager requestWhenInUseAuthorization];
}
if ([_manager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[_manager requestAlwaysAuthorization];
}
}
3. 在-Supporting Files文件夾下的Info.plist添加一個boolean類型的鍵值對NSLocationWhenInUseUsageDescription
, 并設(shè)為YES, 如下圖所示
4. 遵守協(xié)議<CLLocationManagerDelegate>
, 實現(xiàn)代理方法
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"error:%@", error);
}
// iOS6之前
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
}
// 定位成功后
// iOS6之后
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
if (locations.count > 0) {
// 獲取位置信息
CLLocation *loc = [locations lastObject];
CLLocationCoordinate2D coor = loc.coordinate;
// NSLog(@"%@", locations);
NSLog(@"latitude: %lf, longitude: %lf", coor.latitude, coor.longitude);
/*
計算速度
速度 = 位移 / 時間
*/
// if (_lastLoc) {
//
// // 計算位置 將一個位置設(shè)為成員變量
// CLLocationDistance dis = [loc distanceFromLocation:_lastLoc];
// // 計算時間
// NSTimeInterval time = [loc.timestamp timeIntervalSinceDate:_lastLoc.timestamp];
//
// CGFloat speed = dis / time;
//
// _lastLoc = loc;
// }
}
// 關(guān)閉定位
[_manager stopUpdatingLocation];
// 關(guān)閉獲取定位方向
// [_manager stopUpdatingHeading];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
// 相對地理北極的方向
// newHeading.trueHeading;
// 相對磁北極的方向
// newHeading.magneticHeading;
}
二. 系統(tǒng)地圖
1. 導(dǎo)入MapKit/MapKit.h
, 創(chuàng)建地圖視圖對象成員變量
@interface ViewController () <MKMapViewDelegate>
{
// 地圖對象
MKMapView *_mapView;
}
2. 新建地圖對象, 設(shè)置屬性
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 1. 創(chuàng)建地圖對象
_mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 20, 320, 568 - 20)];
// 2. 地圖類型
/*
MKMapTypeStandard,
MKMapTypeSatellite,
MKMapTypeHybrid
*/
_mapView.mapType = MKMapTypeHybrid;
// 3. 設(shè)置代理
_mapView.delegate = self;
// 4. 顯示地圖
[self.view addSubview:_mapView];
// 5. 設(shè)置地圖的位置
// 中心點
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(31, 121);
// center = {32, 122}; 另一種創(chuàng)建結(jié)構(gòu)體的方式
// span 0-1
MKCoordinateSpan span = MKCoordinateSpanMake(0.2, 0.2);
// 區(qū)域
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
_mapView.region = region;
}
3. 定位到所在位置: 創(chuàng)建定位管理對象, 遵守CLLocationManagerDelegate協(xié)議, 實現(xiàn)協(xié)議方法
- (void)viewDidLoad {
[super viewDidLoad];
// 開啟定位功能
_manager = [[CLLocationManager alloc] init];
// 每隔多少距離使用位置更新數(shù)據(jù)
_manager.distanceFilter = 50;
// 定位的精度
_manager.desiredAccuracy = kCLLocationAccuracyBest;
// 代理屬性
_manager.delegate = self;
[_manager startUpdatingLocation];
// iOS8
// NSLocationWhenInUseUsageDescription == YES;
if ([_manager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[_manager requestWhenInUseAuthorization];
}
// 地圖對象
…………………………………………………………………………………………
// 6. 顯示定位位置
_mapView.showsUserLocation = YES;
}
#pragma mark - CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"error:%@", error);
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
if (locations.count > 0) {
CLLocation *loc = locations[0];
// 將地圖位置設(shè)置地圖的中心點
[_mapView setCenterCoordinate:loc.coordinate animated:YES];
}
}
三. 系統(tǒng)地圖的大頭針
1. 設(shè)置好地圖和大頭針(大頭針暫時不會顯示)
#import "ViewController.h"
#import <MapKit/MapKit.h>
@interface ViewController ()
{
MKMapView *_mapView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 創(chuàng)建一個視圖
_mapView = [[MKMapView alloc] initWithFrame:CGRectMake(30, 100, 300, 500)];
_mapView.mapType = MKMapTypeStandard;
[self.view addSubview: _mapView];
// 設(shè)置區(qū)域
// 1. 中心點
/*
typedef struct {
CLLocationDegrees latitude;
CLLocationDegrees longitude;
} CLLocationCoordinate2D;
*/
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(39, 116);
// 2. 半徑
/*
typedef struct {
CLLocationDegrees latitudeDelta;
CLLocationDegrees longitudeDelta;
} MKCoordinateSpan;
*/
MKCoordinateSpan span = MKCoordinateSpanMake(0.2, 0.2);
// 3. 區(qū)域
/*
typedef struct {
CLLocationCoordinate2D center;
MKCoordinateSpan span;
} MKCoordinateRegion;
*/
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
_mapView.region = region;
// 添加一個長按手勢, 點擊后, 在這個位置加一個大頭針
// 在實際項目中, 需要去請求一個接口, 返回的數(shù)據(jù)對象中會包含每個對象的經(jīng)緯度信息, 然后根據(jù)經(jīng)緯度去顯示一個大頭針
[_mapView addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)]];
}
- (void)longPressAction:(UILongPressGestureRecognizer *)gesture
{
// 獲取經(jīng)緯度信息
CGPoint point = [gesture locationInView:_mapView];
// 坐標轉(zhuǎn)換為經(jīng)緯度
CLLocationCoordinate2D coor = [_mapView convertPoint:point toCoordinateFromView:_mapView];
// 添加大頭針
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
// 設(shè)置經(jīng)緯度
annotation.coordinate = coor;
// 標題
annotation.title = @"大標題";
// 小標題
annotation.subtitle = @"小標題";
[_mapView addAnnotation:annotation];
}
2. 顯示大頭針, 以及大頭針的標題: 設(shè)置地圖對象的代理, 遵守MKMapViewDelegate
協(xié)議
- (void)viewDidLoad {
…………………………………………………………………………………………
_mapView.delegate = self;
}
#pragma mark - MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
// 重用ID
static NSString *annotationId = @"annotationId";
// 從重用隊列中獲取
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:annotationId];
if (nil == annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationId];
}
// 設(shè)置屬性
annotationView.canShowCallout = YES;
return annotationView;
}
3. 點擊大頭針, 在彈出的視圖左右顯示視圖(如果是UIControl的子類的話, 點擊調(diào)用的方法要實現(xiàn)代理方法 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
里面)
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
…………………………………………………………………………………………
// 在左邊顯示圖片
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
imageView.image = [UIImage imageNamed:@"blue.png"];
annotationView.leftCalloutAccessoryView = imageView;
// 在右邊顯示一個按鈕
UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.rightCalloutAccessoryView = btn;
return annotationView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"%s", __func__);
}
四. 自定義大頭針
1. 自定義大頭針類MyAnnotation
(需要遵守MKAnnotation
協(xié)議, 需要自己設(shè)標題, 副標題, 經(jīng)緯度; 不需要設(shè)置左右兩個視圖)
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
/*
自定義大頭針類型
title: 標題
subtitle: 小標題
*/
@interface MyAnnotation : NSObject <MKAnnotation>
- (instancetype)initWithCoor:(CLLocationCoordinate2D)coor title:(NSString *)title subtitle:(NSString *)subTitle;
@end
#import "MyAnnotation.h"
@implementation MyAnnotation
{
// 經(jīng)緯度
CLLocationCoordinate2D _myCoor;
// 標題
NSString *_myTitle;
// 副標題
NSString *_mySubtitle;
}
- (instancetype)initWithCoor:(CLLocationCoordinate2D)coor title:(NSString *)title subtitle:(NSString *)subtitle
{
if (self = [super init]) {
_myCoor = coor;
_myTitle = title;
_mySubtitle = subtitle;
}
return self;
}
#pragma mark - MKAnnotation
- (NSString *)title
{
return _myTitle;
}
- (NSString *)subtitle
{
return _mySubtitle;
}
- (CLLocationCoordinate2D)coordinate
{
return _myCoor;
}
@end
2. 顯示mapView, 在mapView上添加長按手勢以添加自定義Annotation, 在代理方法中- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
中顯示Annotation(可以設(shè)置Annotation的圖片, 添加左右CalloutAccessoryView)
#pragma mark - MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *annoId = @"annoId";
MKAnnotationView *annoView = [mapView dequeueReusableAnnotationViewWithIdentifier:annoId];
if (nil == annoView) {
annoView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annoId];
}
annoView.image = [UIImage imageNamed:@"mark"];
annoView.canShowCallout = YES;
// 右邊添加按鈕
UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annoView.rightCalloutAccessoryView = btn;
return annoView;
}
3. 之后就可以通過一些設(shè)置來彈出視圖, 傳參......
五. 系統(tǒng)地圖的地址解析和反地址解析
地址解析: 將地址解析為經(jīng)緯度
反地址解析: 將經(jīng)緯度解析為地址
#import "ViewController.h"
#import "MyUtility.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()
{
// 地址輸入框
UITextField *_addressTextField;
// 經(jīng)緯度
UITextField *_latitudeTextField;
UITextField *_longitudeTextField;
// 解析對象
CLGeocoder *_geocoder;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self createView];
// 初始化解析對象
_geocoder = [[CLGeocoder alloc] init];
}
- (void)createView
{
// 地址
_addressTextField = [MyUtility createTextField:CGRectMake(30, 100, 200, 40) placeHolder:@"請輸入地址"];
[self.view addSubview:_addressTextField];
UIButton *parserBtn = [MyUtility createButtonWithFrame:CGRectMake(240, 100, 60, 40) title:@"解析" backgroundImageName:nil target:self action:@selector(geoAction)];
[self.view addSubview:parserBtn];
// 經(jīng)緯度
_latitudeTextField = [MyUtility createTextField:CGRectMake(30, 200, 90, 40) placeHolder:@"緯度"];
[self.view addSubview:_latitudeTextField];
_longitudeTextField = [MyUtility createTextField:CGRectMake(140, 200, 90, 40) placeHolder:@"經(jīng)度"];
[self.view addSubview:_longitudeTextField];
UIButton *reverseBtn = [MyUtility createButtonWithFrame:CGRectMake(240, 200, 60, 40) title:@"泛解析" backgroundImageName:nil target:self action:@selector(reverseGeoAction)];
[self.view addSubview:reverseBtn];
}
// 地址解析
- (void)geoAction
{
if (_addressTextField.text.length > 0) {
// 解析
[_geocoder geocodeAddressString:_addressTextField.text completionHandler:^(NSArray *placemarks, NSError *error) {
// 解析結(jié)束時調(diào)用該block
NSLog(@"%@", placemarks);
for (CLPlacemark *placemark in placemarks) {
// placemark 是符合條件的地址信息
NSLog(@"ISOcountryCode:%@", placemark.ISOcountryCode);
NSLog(@"administrativeArea:%@", placemark.administrativeArea);
NSLog(@"addressDictionary:%@", placemark.addressDictionary);
NSLog(@"latitude:%lf\nlongitude:%lf", placemark.location.coordinate.latitude, placemark.location.coordinate.longitude);
}
}];
}
}
// 反地址解析
- (void)reverseGeoAction
{
if (_longitudeTextField.text.length > 0 && _latitudeTextField.text.length > 0) {
// 反解析
CLLocation *loc = [[CLLocation alloc] initWithLatitude:_latitudeTextField.text.floatValue longitude:_longitudeTextField.text.floatValue];
[_geocoder reverseGeocodeLocation:loc completionHandler:^(NSArray *placemarks, NSError *error) {
for (CLPlacemark *placemark in placemarks) {
NSLog(@"%@", placemark.addressDictionary);
NSLog(@"%@", [placemark.addressDictionary objectForKey:@"City"]);
}
}];
}
}
六. 高德地圖
1. 前期準備: 按照官網(wǎng)教程
2. 顯示地圖, 搜索地點, 地址解碼和反解碼的示例代碼
#import "MyUtility.h"
#import "ViewController.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapSearchKit/AMapSearchAPI.h>
#define kAMapKey (@"97ae63c2d20ed3b23767312e2d2ab609")
@interface ViewController () <MAMapViewDelegate, AMapSearchDelegate>
{
// 地圖
MAMapView *_mapView;
// 搜索對象(搜索, 解析都需要該對象)
AMapSearchAPI *_searchAPI;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 設(shè)置key值
[MAMapServices sharedServices].apiKey = kAMapKey;
_searchAPI =[[AMapSearchAPI alloc] initWithSearchKey:kAMapKey Delegate:self];
// 創(chuàng)建高德地圖
_mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 100, 320, 568 - 100)];
_mapView.mapType = MAMapTypeStandard;
_mapView.delegate = self;
[self.view addSubview:_mapView];
// 添加三個按鈕
[self createThreeButton];
}
- (void)createThreeButton
{
UIButton *addSearchButton = [MyUtility createButtonWithFrame:CGRectMake(30, 30, 100, 40) title:@"搜地址" backgroundImageName:nil target:self action:@selector(searchPalce)];
UIButton *geocoderButton = [MyUtility createButtonWithFrame:CGRectMake(140, 30, 100, 40) title:@"解析" backgroundImageName:nil target:self action:@selector(geocoderAction)];
UIButton *reverseGeocoderButton = [MyUtility createButtonWithFrame:CGRectMake(250, 30, 60, 40) title:@"反解析" backgroundImageName:nil target:self action:@selector(reverseGeocoderAction)];
[self.view addSubview:addSearchButton];
[self.view addSubview:geocoderButton];
[self.view addSubview:reverseGeocoderButton];
}
- (void)searchPalce
{
AMapPlaceSearchRequest *request = [[AMapPlaceSearchRequest alloc] init];
// 設(shè)置搜索的類型
request.searchType = AMapSearchType_PlaceKeyword;
// 城市的數(shù)組
request.city = @[@"北京"];
// 搜索關(guān)鍵字
request.keywords = @"江南";
// 搜索
[_searchAPI AMapPlaceSearch:request];
}
// 地址解析
- (void)geocoderAction
{
AMapGeocodeSearchRequest *request = [[AMapGeocodeSearchRequest alloc] init];
// 類型
request.searchType = AMapSearchType_Geocode;
// 城市
request.city = @[@"beijing"];
// 地址
request.address = @"天安門";
// 搜索
[_searchAPI AMapGeocodeSearch:request];
}
- (void)reverseGeocoderAction
{
AMapReGeocodeSearchRequest *request = [[AMapReGeocodeSearchRequest alloc] init];
// 類型
request.searchType = AMapSearchType_ReGeocode;
// 設(shè)置經(jīng)緯度
AMapGeoPoint *point = [[AMapGeoPoint alloc] init];
point.latitude = 31;
point.longitude = 121;
request.location = point;
// 是否返回擴展信息
request.requireExtension = YES;
[_searchAPI AMapReGoecodeSearch:request];
}
- (void)obtainBundleIdentifier
{
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSLog(@"%@", bundleIdentifier);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - AMapSearchAPI代理
// 地址搜索
- (void)onPlaceSearchDone:(AMapPlaceSearchRequest *)request response:(AMapPlaceSearchResponse *)response
{
NSMutableArray *array = [NSMutableArray array];
for (AMapPOI *poi in response.pois) {
// poi.location.latitude
// 創(chuàng)建一個大頭針對象
MAPointAnnotation *anno = [[MAPointAnnotation alloc] init];
anno.coordinate = CLLocationCoordinate2DMake(poi.location.latitude, poi.location.longitude);
anno.title = poi.name;
anno.subtitle = poi.city;
[array addObject:anno];
}
// 移除之前的大頭針
[_mapView removeAnnotations:_mapView.annotations];
// 添加到地圖上
[_mapView addAnnotations:array];
}
// 地址解析
- (void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response
{
NSMutableArray *array = [NSMutableArray array];
for (AMapGeocode *geoCode in response.geocodes) {
// 創(chuàng)建大頭針
MAPointAnnotation *anno = [[MAPointAnnotation alloc] init];
anno.coordinate = CLLocationCoordinate2DMake(geoCode.location.latitude, geoCode.location.longitude);
anno.title = geoCode.formattedAddress;
[array addObject:anno];
}
// 移除之前的大頭針
[_mapView removeAnnotations:_mapView.annotations];
// 添加到地圖上
[_mapView addAnnotations:array];
}
- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response
{
NSLog(@"%@", response.regeocode.formattedAddress);
AMapPlaceSearchRequest *request1 = [[AMapPlaceSearchRequest alloc] init];
// 設(shè)置搜索的類型
request1.searchType = AMapSearchType_PlaceKeyword;
// 城市的數(shù)組
request1.city = @[@"上海"];
// 搜索關(guān)鍵字
request1.keywords = response.regeocode.formattedAddress;
// 搜索
[_searchAPI AMapPlaceSearch:request1];
}
#pragma mark - MAMapView代理
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
static NSString *annoId = @"annoId";
MAAnnotationView *annoView = [mapView dequeueReusableAnnotationViewWithIdentifier:annoId];
if (nil == annoView) {
annoView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annoId];
}
annoView.canShowCallout = YES;
return annoView;
}
@end