iOS 고 덕 지도 모방 위 챗 발송 실시 간 위치
-현재 위치 로
-현재 위치 근처 의 Poi 위치 지정 가능
-대상 위 치 를 스스로 검색 하여 근처 의 포 이 를 전시 할 수 있 음
-현재 위 치 를 선택 하거나 대상 위 치 를 선택 하여 발송
 
 준비 작업
1.먼저 고 덕 지도 홈 페이지 에 가서 관련 SDK 를 다운로드 합 니 다(아래 그림).
 
 2.고 덕 지도 홈 페이지 의 절차 에 따라 필요 한 의존 라 이브 러 리 추가
 
 3.프로젝트 의 bundleID 에 따라 고 덕 맵 API 에 인용 을 만 들 고 관련 key 를 신청 합 니 다.
고 덕 지도 응용 관리 배경
이 단계 까지 의 초기 준비 작업 은 거의 차이 가 많 지 않다.물론 저 는 구체 적 으로 쓰 지 않 았 습 니 다.상세 하 게 고 덕 지도 SDK 를 도입 하려 면 인내심 을 가지 고 고 고 덕 지도 홈 페이지 SDK 에 따라 한 걸음 한 걸음 조작 해 야 합 니 다.
코드 부분
1.고 덕 지도 SDK 초기 화
AppleDelegate 에 관련 헤더 파일 을 도입 하여 고 덕 지도 응용 관리 에서 이 응용 프로그램 이 사용 하 는 key 값 을 찾 아 고 덕 지도 SDK 를 초기 화 합 니 다.코드 부분 직접 붙 이기:
#import "AppDelegate.h"
#import "ViewController.h"
#import <AMapLocationKit/AMapLocationKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>
static NSString *APIKey = @"a1500980e29b7ca7612a46c19e0d2e3a";
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  [self.window makeKeyAndVisible];
  self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[ViewController new]];
  [AMapServices sharedServices].apiKey = APIKey;
  
  return YES;
}위치 추적 이 필요 한 클래스 에 지도 와 관련 된 헤더 파일 을 가 져 옵 니 다.
지도 보기 초기 화:
- (void)initMapView{
  self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 64 + 44, SCREEN_WIDTH, 300)];
  self.mapView.delegate = self;
  self.mapView.mapType = MAMapTypeStandard;
  self.mapView.showsScale = NO;
  self.mapView.showsCompass = NO;
  self.mapView.showsUserLocation = YES;
  [self.view addSubview:self.mapView];
  
  UIButton *localButton = [UIButton buttonWithType:UIButtonTypeCustom];
  localButton.backgroundColor = [UIColor redColor];
  localButton.frame = CGRectMake(SCREEN_WIDTH - 60, 240, 50, 50);
  [localButton addTarget:self action:@selector(localButtonAction) forControlEvents:UIControlEventTouchUpInside];
  localButton.layer.cornerRadius = 25;
  localButton.clipsToBounds = YES;
  [localButton setImage:[UIImage imageNamed:@"  "] forState:UIControlStateNormal];
  [self.mapView addSubview:localButton];
  
}
//   SDK
- (void)configLocationManager {
  self.locationManager = [[AMapLocationManager alloc] init];
  [self.locationManager setDelegate:self];
  [self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
  //        
  [self.locationManager setLocationTimeout:6];
  [self.locationManager setReGeocodeTimeout:3];
}
- (void)locateAction {
  [self showHudInView:self.view hint:@"    ..."];
  //         
  [self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
    if (error) {
      [self showHint:@"    " yOffset:-180];
      NSLog(@"locError:{%ld - %@};",(long)error.code,error.localizedDescription);
      if (error.code == AMapLocationErrorLocateFailed) {
        return ;
      }
    }
    //    
    NSLog(@"location:%@", location);
    if (regeocode)
    {
      [self hideHud];
      self.currentLocationCoordinate = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude);
      self.city = regeocode.city;
      [self showMapPoint];
      [self setCenterPoint];
      self.request.location = [AMapGeoPoint locationWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude];
      [self.mapSearch AMapPOIAroundSearch:self.request];
    }
  }];
}
- (void)showMapPoint{
  [_mapView setZoomLevel:15.1 animated:YES];
  [_mapView setCenterCoordinate:self.currentLocationCoordinate animated:YES];
}
- (void)setCenterPoint{
  MAPointAnnotation * centerAnnotation = [[MAPointAnnotation alloc] init];//       
  centerAnnotation.coordinate = self.currentLocationCoordinate;//     
  centerAnnotation.title = @"";
  centerAnnotation.subtitle = @"";
  [self.mapView addAnnotation:centerAnnotation];//    
  
}
#pragma mark - MAMapView Delegate
- (MAAnnotationView *)mapView:(MAMapView *)mapView
      viewForAnnotation:(id<MAAnnotation>)annotation {
  if ([annotation isKindOfClass:[MAPointAnnotation class]]) {
    static NSString *pointReuseIndentifier = @"pointReuseIndentifier";
    MAPinAnnotationView*annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
    if (annotationView == nil)
    {
      annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier];
    }
    annotationView.canShowCallout= YES;    //        ,   NO
    annotationView.animatesDrop = YES;    //        ,   NO
    annotationView.draggable = YES;    //        ,   NO
    annotationView.pinColor = MAPinAnnotationColorRed;
    return annotationView;
  }
  return nil;
}
- (void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
  [self.mapView removeAnnotations:self.mapView.annotations];
  
  CLLocationCoordinate2D centerCoordinate = mapView.region.center;
  self.currentLocationCoordinate = centerCoordinate;
  
  MAPointAnnotation * centerAnnotation = [[MAPointAnnotation alloc] init];
  centerAnnotation.coordinate = centerCoordinate;
  centerAnnotation.title = @"";
  centerAnnotation.subtitle = @"";
  [self.mapView addAnnotation:centerAnnotation];
  //          
  if (!self.isSelectedAddress) {
    [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
    self.selectedIndexPath=[NSIndexPath indexPathForRow:0 inSection:0];
    self.request.location = [AMapGeoPoint locationWithLatitude:centerCoordinate.latitude longitude:centerCoordinate.longitude];
    self.currentPage = 1;
    self.request.page = self.currentPage;
    [self.mapSearch AMapPOIAroundSearch:self.request];
  }
  self.isSelectedAddress = NO;
}github 주소:https://github.com/XuZzzzzzzz/XCLocation
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
View의 레이아웃 방법을 AutoLayout에서 따뜻한 손 계산으로 하면 성능이 9.26배로 된 이야기이 기사는 의 15 일째 기사입니다. 어제는 에서 이었습니다. 손 계산을 권하는 의도는 없고, 특수한 상황하에서 계측한 내용입니다 화면 높이의 10 배 정도의 contentView가있는 UIScrollView 레이아...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.