Repository: hadesh/tripdemo Branch: master Commit: edfbb97291f5 Files: 44 Total size: 119.3 KB Directory structure: gitextract_73blthgo/ ├── .gitignore ├── Podfile ├── README.md ├── TripDemo/ │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj/ │ │ └── Main.storyboard │ ├── CommonUtility.h │ ├── CommonUtility.m │ ├── DDDriver.h │ ├── DDDriver.m │ ├── DDDriverManager.h │ ├── DDDriverManager.m │ ├── DDLocation.h │ ├── DDLocation.m │ ├── DDLocationControl.h │ ├── DDLocationControl.m │ ├── DDLocationView.h │ ├── DDLocationView.m │ ├── DDSearchManager.h │ ├── DDSearchManager.m │ ├── DDSearchViewController.h │ ├── DDSearchViewController.m │ ├── DDTaxiCallRequest.h │ ├── DDTaxiCallRequest.m │ ├── Images.xcassets/ │ │ ├── AppIcon.appiconset/ │ │ │ └── Contents.json │ │ └── LaunchImage.launchimage/ │ │ └── Contents.json │ ├── Info.plist │ ├── Launch Screen.xib │ ├── MANaviRoute.h │ ├── MANaviRoute.m │ ├── MovingAnnotation/ │ │ ├── CACoordLayer.h │ │ ├── CACoordLayer.m │ │ ├── MovingAnnotationView.h │ │ └── MovingAnnotationView.m │ ├── Toast+UIView.h │ ├── Toast+UIView.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── TripDemo.xcodeproj/ │ ├── project.pbxproj │ └── project.xcworkspace/ │ └── contents.xcworkspacedata ├── TripDemo.xcworkspace/ │ └── contents.xcworkspacedata └── TripDemoTests/ ├── Info.plist └── TripDemoTests.m ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Xcode # # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore ## Build generated build/ DerivedData ## Various settings *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdata ## Other *.xccheckout *.moved-aside *.xcuserstate *.xcscmblueprint ## Obj-C/Swift specific *.hmap *.ipa # CocoaPods # # We recommend against adding the Pods directory to your .gitignore. However # you should judge for yourself, the pros and cons are mentioned at: # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control # Pods/ # Carthage # # Add this line if you want to avoid checking in source code from Carthage dependencies. # Carthage/Checkouts Carthage/Build ================================================ FILE: Podfile ================================================ platform :ios, '6.0' target 'TripDemo' do pod 'AMap3DMap' pod 'AMapSearch' pod 'AMapLocation' end ================================================ FILE: README.md ================================================ 高小德用车 ======= 高德地图开放平台出行类解决方案-乘客端(iOS) ### 描述 使用高德地图开放平台相关SDK开发的出行类app乘客端的Demo。 - [出行类解决方案]http://lbs.amap.com/smart/car/ - [iOS相关SDK]http://lbs.amap.com/api/ios-sdk/summary/ - [开放平台社区]http://lbsbbs.amap.com/portal.php ### 说明 Demo中使用了高德地图iOS平台的3D地图SDK和搜索SDK。 DDSearchManager 类封装了搜索SDK的相关功能。 DDDriverManager 用于管理司机相关操作。 ### 截图效果 ![start](snapshots/start.png) ![search](snapshots/search.png) ![end](snapshots/end.png) ================================================ FILE: TripDemo/AppDelegate.h ================================================ // // AppDelegate.h // TripDemo // // Created by xiaoming han on 15/4/2. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; @end ================================================ FILE: TripDemo/AppDelegate.m ================================================ // // AppDelegate.m // TripDemo // // Created by xiaoming han on 15/4/2. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import "AppDelegate.h" #import @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [AMapServices sharedServices].apiKey = @"c51c42708d693e61c4a89e7b4fea195f"; return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end ================================================ FILE: TripDemo/Base.lproj/Main.storyboard ================================================ ================================================ FILE: TripDemo/CommonUtility.h ================================================ // // CommonUtility.h // SearchV3Demo // // Created by songjian on 13-8-22. // Copyright (c) 2013年 songjian. All rights reserved. // #import #import #import @interface CommonUtility : NSObject + (CLLocationCoordinate2D *)coordinatesForString:(NSString *)string coordinateCount:(NSUInteger *)coordinateCount parseToken:(NSString *)token; + (NSArray *)pathForCoordinateString:(NSString *)coordinateString; @end ================================================ FILE: TripDemo/CommonUtility.m ================================================ // // CommonUtility.m // SearchV3Demo // // Created by songjian on 13-8-22. // Copyright (c) 2013年 songjian. All rights reserved. // #import "CommonUtility.h" @implementation CommonUtility + (CLLocationCoordinate2D *)coordinatesForString:(NSString *)string coordinateCount:(NSUInteger *)coordinateCount parseToken:(NSString *)token { if (string == nil) { return NULL; } if (token == nil) { token = @","; } NSString *str = @""; if (![token isEqualToString:@","]) { str = [string stringByReplacingOccurrencesOfString:token withString:@","]; } else { str = [NSString stringWithString:string]; } NSArray *components = [str componentsSeparatedByString:@","]; NSUInteger count = [components count] / 2; if (coordinateCount != NULL) { *coordinateCount = count; } CLLocationCoordinate2D *coordinates = (CLLocationCoordinate2D*)malloc(count * sizeof(CLLocationCoordinate2D)); for (int i = 0; i < count; i++) { coordinates[i].longitude = [[components objectAtIndex:2 * i] doubleValue]; coordinates[i].latitude = [[components objectAtIndex:2 * i + 1] doubleValue]; } return coordinates; } + (NSArray *)pathForCoordinateString:(NSString *)coordinateString { if (coordinateString.length == 0) { return nil; } NSUInteger count = 0; CLLocationCoordinate2D *coordinates = [CommonUtility coordinatesForString:coordinateString coordinateCount:&count parseToken:@";"]; NSMutableArray * path = [NSMutableArray arrayWithCapacity:count]; for (int i = 0; i < count; i++) { CLLocation * loc = [[CLLocation alloc] initWithCoordinate:coordinates[i] altitude:0.0 horizontalAccuracy:0.0 verticalAccuracy:0.0 timestamp:[NSDate date]]; [path addObject:loc]; } return path; } @end ================================================ FILE: TripDemo/DDDriver.h ================================================ // // DDDriver.h // TripDemo // // Created by yi chen on 4/3/15. // Copyright (c) 2015 AutoNavi. All rights reserved. // #import #import @interface DDDriver : NSObject @property (nonatomic, strong) NSString * idInfo; @property (nonatomic, assign) CLLocationCoordinate2D coordinate; + (instancetype)driverWithID:(NSString *)idInfo coordinate:(CLLocationCoordinate2D)coordinate; - (id)initWithID:(NSString *)idInfo coordinate:(CLLocationCoordinate2D)coordinate; @end ================================================ FILE: TripDemo/DDDriver.m ================================================ // // DDDriver.m // TripDemo // // Created by yi chen on 4/3/15. // Copyright (c) 2015 AutoNavi. All rights reserved. // #import "DDDriver.h" @implementation DDDriver + (instancetype)driverWithID:(NSString *)idInfo coordinate:(CLLocationCoordinate2D)coordinate { return [[self alloc] initWithID:idInfo coordinate:coordinate]; } - (id)initWithID:(NSString *)idInfo coordinate:(CLLocationCoordinate2D)coordinate { if (self = [super init]) { self.idInfo = idInfo; self.coordinate = coordinate; } return self; } @end ================================================ FILE: TripDemo/DDDriverManager.h ================================================ // // DDDriverManager.h // TripDemo // // Created by yi chen on 4/3/15. // Copyright (c) 2015 AutoNavi. All rights reserved. // #import #import #import "DDTaxiCallRequest.h" #import "DDDriver.h" @protocol DDDriverManagerDelegate; /** * 司机相关管理类。获取司机数据、发送用车请求等。 */ @interface DDDriverManager : NSObject @property (nonatomic, weak) id delegate; //根据mapRect取司机数据 - (void)searchDriversWithinMapRect:(MAMapRect)mapRect; //发送用车请求:起点终点 - (BOOL)callTaxiWithRequest:(DDTaxiCallRequest *)request; @end @protocol DDDriverManagerDelegate @optional //返回司机数据结果 - (void)searchDoneInMapRect:(MAMapRect)mapRect withDriversResult:(NSArray *)drivers timestamp:(NSTimeInterval)timestamp; //司机选择结果 - (void)callTaxiDoneWithRequest:(DDTaxiCallRequest *)request Taxi:(DDDriver *)driver; //司机位置更新 - (void)onUpdatingLocations:(NSArray *)locations forDriver:(DDDriver *)driver; @end ================================================ FILE: TripDemo/DDDriverManager.m ================================================ // // DDDriverManager.m // TripDemo // // Created by yi chen on 4/3/15. // Copyright (c) 2015 AutoNavi. All rights reserved. // #import "DDDriverManager.h" #import #import "MANaviRoute.h" #import "DDSearchManager.h" @interface DDDriverManager() @property(nonatomic, strong) DDTaxiCallRequest * currentRequest; @property(nonatomic, strong) DDDriver * selectDriver; @property(nonatomic, strong) NSArray * driverPath; @property(nonatomic, assign) NSUInteger subpathIdx; @end @implementation DDDriverManager { } //根据mapRect取司机数据 - (void)searchDriversWithinMapRect:(MAMapRect)mapRect { //在mapRect区域里随机生成coordinate #define MAX_COUNT 50 #define MIN_COUNT 5 NSUInteger randCount = arc4random() % MAX_COUNT + MIN_COUNT; NSMutableArray * drivers = [NSMutableArray arrayWithCapacity:randCount]; for (int i = 0; i < randCount; i++) { DDDriver * driver = [DDDriver driverWithID:@"京B****" coordinate:[self randomPointInMapRect:mapRect]]; [drivers addObject:driver]; } //回调返回司机数据 if (self.delegate && [self.delegate respondsToSelector:@selector(searchDoneInMapRect:withDriversResult:timestamp:)]) { [self.delegate searchDoneInMapRect:mapRect withDriversResult:drivers timestamp:[NSDate date].timeIntervalSinceReferenceDate]; } } //发送用车请求:起点终点 - (BOOL)callTaxiWithRequest:(DDTaxiCallRequest *)request { if (request.start == nil || request.end == nil) { return NO; } _currentRequest = request; //在起点附近随机生成司机位置 #define startAroundRangeMeters 500.0 MAMapRect startAround = MAMapRectForCoordinateRegion(MACoordinateRegionMakeWithDistance(_currentRequest.start.coordinate, startAroundRangeMeters, startAroundRangeMeters)); CLLocationCoordinate2D driverLocation = [self randomPointInMapRect:startAround]; NSLog(@"driverLocation : %f %f", driverLocation.latitude, driverLocation.longitude); _selectDriver = [DDDriver driverWithID:@"京B****" coordinate:driverLocation]; //延迟返回司机选择结果 __weak __typeof(&*self) weakSelf = self; int64_t delayInSeconds = 1.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(callTaxiDoneWithRequest:Taxi:)]) { [weakSelf.delegate callTaxiDoneWithRequest:_currentRequest Taxi:_selectDriver]; } //司机位置更新 [weakSelf startUpdateLocationForDriver:_selectDriver]; }); return YES; } - (void)startUpdateLocationForDriver:(DDDriver *)driver { [self searchPathFrom:driver.coordinate to:_currentRequest.start.coordinate]; } //找驾车到达乘客位置的路径 - (void)searchPathFrom:(CLLocationCoordinate2D)from to:(CLLocationCoordinate2D)to { AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init]; navi.requireExtension = YES; /* 出发点. */ navi.origin = [AMapGeoPoint locationWithLatitude:from.latitude longitude:from.longitude]; /* 目的地. */ navi.destination = [AMapGeoPoint locationWithLatitude:to.latitude longitude:to.longitude]; __weak __typeof(&*self) weakSelf = self; [[DDSearchManager sharedInstance] searchForRequest:navi completionBlock:^(id request, id response, NSError *error) { AMapRouteSearchResponse *naviResponse = response; NSLog(@"%@", naviResponse); if (naviResponse.route == nil) { return; } //路径解析 MANaviRoute * naviRoute = [MANaviRoute naviRouteForPath:naviResponse.route.paths[0]]; //保存路径串 weakSelf.driverPath = naviRoute.path; weakSelf.subpathIdx = 0; //开始push给乘客端 NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:weakSelf selector:@selector(onUpdatingLocation) userInfo:nil repeats:YES]; [timer fire]; }]; } - (void)onUpdatingLocation { if (self.delegate && [self.delegate respondsToSelector:@selector(onUpdatingLocations:forDriver:)] && _subpathIdx < self.driverPath.count) { [self.delegate onUpdatingLocations:self.driverPath[_subpathIdx++] forDriver:self.selectDriver]; } } #pragma mark - Utility - (CLLocationCoordinate2D)randomPointInMapRect:(MAMapRect)mapRect { MAMapPoint result; result.x = mapRect.origin.x + arc4random() % (int)(mapRect.size.width); result.y = mapRect.origin.y + arc4random() % (int)(mapRect.size.height); return MACoordinateForMapPoint(result); } @end ================================================ FILE: TripDemo/DDLocation.h ================================================ // // DDLocation.h // TripDemo // // Created by xiaoming han on 15/4/2. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import #import /** * 封装位置信息。 */ @interface DDLocation : NSObject @property (nonatomic, assign) CLLocationCoordinate2D coordinate; @property (nonatomic, copy) NSString *name; @property (nonatomic, copy) NSString *cityCode; @property (nonatomic, copy) NSString *address; @end ================================================ FILE: TripDemo/DDLocation.m ================================================ // // DDLocation.m // TripDemo // // Created by xiaoming han on 15/4/2. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import "DDLocation.h" @implementation DDLocation - (NSString *)description { return [NSString stringWithFormat:@"name:%@, cityCode:%@, address:%@, coordinate:%f, %f", self.name, self.cityCode, self.address, self.coordinate.latitude, self.coordinate.longitude]; } @end ================================================ FILE: TripDemo/DDLocationControl.h ================================================ // // DDLocationControl.h // TripDemo // // Created by xiaoming han on 15/4/3. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import @interface DDLocationControl : UIControl @property (nonatomic, copy) NSString *title; @property (nonatomic, strong) UIImage *accessoryImage; @end ================================================ FILE: TripDemo/DDLocationControl.m ================================================ // // DDLocationControl.m // TripDemo // // Created by xiaoming han on 15/4/3. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import "DDLocationControl.h" #define kDefaultAccessoryViewSize 32 #define kDefaultAccessoryViewMargin 5 @interface DDLocationControl () { UILabel *_titleLabel; UIImageView *_leftAccessoryView; UIImageView *_rightAccessoryView; CALayer *_highLightLayer; } @end @implementation DDLocationControl - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor whiteColor]; _highLightLayer = [CALayer layer]; _highLightLayer.frame = self.bounds; _highLightLayer.backgroundColor = [UIColor clearColor].CGColor; [self.layer addSublayer:_highLightLayer]; _leftAccessoryView = [[UIImageView alloc] initWithFrame:CGRectZero]; _rightAccessoryView = [[UIImageView alloc] initWithFrame:CGRectZero]; _rightAccessoryView.alpha = 0.4; _rightAccessoryView.image = [UIImage imageNamed:@"icon_next"]; [self addSubview:_leftAccessoryView]; [self addSubview:_rightAccessoryView]; _titleLabel = [[UILabel alloc] initWithFrame:self.bounds]; _titleLabel.textAlignment = NSTextAlignmentLeft; [self addSubview:_titleLabel]; } return self; } - (void)layoutSubviews { _highLightLayer.frame = self.bounds; CGFloat accessoryViewSize = kDefaultAccessoryViewSize > CGRectGetHeight(self.bounds) ? CGRectGetHeight(self.bounds) : kDefaultAccessoryViewSize; CGFloat accessoryViewY = (CGRectGetHeight(self.bounds) - kDefaultAccessoryViewSize) / 2.0; _leftAccessoryView.frame = CGRectMake(kDefaultAccessoryViewMargin, accessoryViewY, accessoryViewSize, accessoryViewSize); _titleLabel.frame = CGRectMake(accessoryViewSize + kDefaultAccessoryViewMargin * 2, 0, CGRectGetWidth(self.bounds) - (accessoryViewSize + kDefaultAccessoryViewMargin) * 2, CGRectGetHeight(self.bounds)); _rightAccessoryView.frame = CGRectMake(CGRectGetMaxX(_titleLabel.frame) + kDefaultAccessoryViewMargin, (CGRectGetHeight(self.bounds) - _rightAccessoryView.image.size.height) / 2.0, _rightAccessoryView.image.size.width, _rightAccessoryView.image.size.height); } - (void)setHighlighted:(BOOL)highlighted { [super setHighlighted:highlighted]; if (highlighted) { _highLightLayer.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.4].CGColor; } else { _highLightLayer.backgroundColor = [UIColor clearColor].CGColor; } } #pragma mark - - (void)setAccessoryImage:(UIImage *)accessoryImage { if (_leftAccessoryView.image == accessoryImage) { return; } _leftAccessoryView.image = accessoryImage; } - (UIImage *)accessoryImage { return _leftAccessoryView.image; } - (NSString *)title { return _titleLabel.text; } - (void)setTitle:(NSString *)title { _titleLabel.text = title; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end ================================================ FILE: TripDemo/DDLocationView.h ================================================ // // DDLocationView.h // TripDemo // // Created by xiaoming han on 15/4/2. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import @class DDLocation; @class DDLocationView; @protocol DDLocationViewDelegate @optional - (void)didClickStartLocation:(DDLocationView *)locationView; - (void)didClickEndLocation:(DDLocationView *)locationView; @end /** * 显示起始位置以及路径信息的视图。 */ @interface DDLocationView : UIView @property (nonatomic, assign) id delegate; @property (nonatomic, strong) DDLocation *startLocation; @property (nonatomic, strong) DDLocation *endLocation; @property (nonatomic, copy) NSString *info; @end ================================================ FILE: TripDemo/DDLocationView.m ================================================ // // DDLocationView.m // TripDemo // // Created by xiaoming han on 15/4/2. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import "DDLocationView.h" #import "DDLocation.h" #import "DDLocationControl.h" #import "DDSearchManager.h" @interface DDLocationView () { DDLocationControl *_startControl; DDLocationControl *_endControl; UILabel * _costControl; CGFloat _originHeight; CALayer *_lineLayer; } @end @implementation DDLocationView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor whiteColor]; self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowOffset = CGSizeMake(1, 1); self.layer.shadowOpacity = 0.3; _originHeight = frame.size.height; _lineLayer = [CALayer layer]; _lineLayer.backgroundColor = [UIColor lightGrayColor].CGColor; _lineLayer.frame = CGRectMake(0, _originHeight, frame.size.width, 1); _lineLayer.hidden = YES; [self.layer addSublayer:_lineLayer]; [self initStartControl]; } return self; } - (void)dealloc { if (_startLocation) { [_startLocation removeObserver:self forKeyPath:@"name"]; } if (_endLocation) { [_endLocation removeObserver:self forKeyPath:@"name"]; } } - (void)initStartControl { if (!_startControl) { _startControl = [[DDLocationControl alloc] initWithFrame:self.bounds]; [self addSubview:_startControl]; _startControl.accessoryImage = [UIImage imageNamed:@"startPoint"]; _startControl.title = @"定位中..."; [_startControl addTarget:self action:@selector(actionStartClick:) forControlEvents:UIControlEventTouchUpInside]; } } - (void)initEndControl { if (!_endControl) { _endControl = [[DDLocationControl alloc] initWithFrame:self.bounds]; _endControl.hidden = YES; [self addSubview:_endControl]; _endControl.accessoryImage = [UIImage imageNamed:@"endPoint"]; [_endControl addTarget:self action:@selector(actionEndClick:) forControlEvents:UIControlEventTouchUpInside]; } } - (void)initCostControl { if (!_costControl) { _costControl = [[UILabel alloc] initWithFrame:self.bounds]; _costControl.hidden = YES; _costControl.textAlignment = NSTextAlignmentCenter; _costControl.textColor = [UIColor whiteColor]; _costControl.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.5]; _costControl.adjustsFontSizeToFitWidth = YES; [self addSubview:_costControl]; } } #pragma mark - Helpers - (void)updateStartControl { if (_startLocation.name.length == 0) { _startControl.title = @"定位中..."; } else { _startControl.title = _startLocation.name; } } - (void)updateEndControl { [self initEndControl]; if (_endLocation.name.length == 0) { self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, _originHeight); _lineLayer.hidden = YES; _endControl.hidden = YES; } else { self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, _originHeight * 2 + 1); _lineLayer.hidden = NO; _endControl.hidden = NO; _endControl.frame = CGRectMake(0, _originHeight + 1, CGRectGetWidth(_startControl.bounds), CGRectGetHeight(_startControl.bounds)); _endControl.title = _endLocation.name; } } - (void)updateCostControl { if (_info.length > 0) { [self initCostControl]; self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, _originHeight * 2.5 + 1); _costControl.hidden = NO; _costControl.frame = CGRectMake(0, CGRectGetHeight(_startControl.bounds) + CGRectGetHeight(_endControl.bounds) + 1, CGRectGetWidth(_startControl.bounds), CGRectGetHeight(_startControl.bounds)* 0.5f); [_costControl setText:_info]; } else { CGFloat height = _endLocation.name.length ? _originHeight * 2 + 1 : _originHeight; self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, height); [_costControl setText:@""]; _costControl.hidden = YES; } } #pragma mark - Public - (void)setStartLocation:(DDLocation *)startLocation { if (_startLocation == startLocation) { return; } [_startLocation removeObserver:self forKeyPath:@"name"]; _startLocation = startLocation; [self updateStartControl]; if (_startLocation) { [_startLocation addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil]; } } - (void)setEndLocation:(DDLocation *)endLocation { if (_endLocation == endLocation) { return; } [_endLocation removeObserver:self forKeyPath:@"name"]; _endLocation = endLocation; [self updateEndControl]; if (_endLocation) { [_endLocation addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil]; } } - (void)setInfo:(NSString *)info { _info = [info copy]; [self updateCostControl]; } #pragma mark - actions - (void)actionStartClick:(UIControl *)sender { if (_delegate && [_delegate respondsToSelector:@selector(didClickStartLocation:)]) { [_delegate didClickStartLocation:self]; } } - (void)actionEndClick:(UIControl *)sender { if (_delegate && [_delegate respondsToSelector:@selector(didClickEndLocation:)]) { [_delegate didClickEndLocation:self]; } } #pragma mark - KVO - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"name"]) { if (object == _startLocation) { [self updateStartControl]; } if (object == _endLocation) { [self updateEndControl]; } } } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end ================================================ FILE: TripDemo/DDSearchManager.h ================================================ // // DDSearchManager.h // TripDemo // // Created by xiaoming han on 15/4/3. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import #import typedef void(^DDSearchCompletionBlock)(id request, id response, NSError *error); /** * 搜索管理类。对高德搜索SDK进行了封装,使用block回调,无需频繁设置代理。 */ @interface DDSearchManager : NSObject + (instancetype)sharedInstance; - (void)searchForRequest:(id)request completionBlock:(DDSearchCompletionBlock)block; @end ================================================ FILE: TripDemo/DDSearchManager.m ================================================ // // DDSearchManager.m // TripDemo // // Created by xiaoming han on 15/4/3. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import "DDSearchManager.h" @interface DDSearchManager () { AMapSearchAPI *_search; NSMapTable *_mapTable; } @end @implementation DDSearchManager + (instancetype)sharedInstance { static id sharedInstance = nil; static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ sharedInstance = [[self alloc] init]; }); return sharedInstance; } - (instancetype)init { self = [super init]; if (self) { _search = [[AMapSearchAPI alloc] init]; _search.delegate = self; _mapTable = [NSMapTable mapTableWithKeyOptions:NSPointerFunctionsStrongMemory valueOptions:NSPointerFunctionsCopyIn]; } return self; } - (void)searchForRequest:(id)request completionBlock:(DDSearchCompletionBlock)block { if ([request isKindOfClass:[AMapPOIKeywordsSearchRequest class]]) { [_search AMapPOIKeywordsSearch:request]; } else if ([request isKindOfClass:[AMapDrivingRouteSearchRequest class]]) { [_search AMapDrivingRouteSearch:request]; } else if ([request isKindOfClass:[AMapInputTipsSearchRequest class]]) { [_search AMapInputTipsSearch:request]; } else if ([request isKindOfClass:[AMapGeocodeSearchRequest class]]) { [_search AMapGeocodeSearch:request]; } else if ([request isKindOfClass:[AMapReGeocodeSearchRequest class]]) { [_search AMapReGoecodeSearch:request]; } else { NSLog(@"unsupported request"); return; } [_mapTable setObject:block forKey:request]; } #pragma mark - Helpers - (void)performBlockWithRequest:(id)request withResponse:(id)response { DDSearchCompletionBlock block = [_mapTable objectForKey:request]; if (block) { block(request, response, nil); } [_mapTable removeObjectForKey:request]; } #pragma mark - AMapSearchDelegate - (void)searchRequest:(id)request didFailWithError:(NSError *)error { DDSearchCompletionBlock block = [_mapTable objectForKey:request]; if (block) { block(request, nil, error); } [_mapTable removeObjectForKey:request]; } - (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response { [self performBlockWithRequest:request withResponse:response]; } - (void)onRouteSearchDone:(AMapRouteSearchBaseRequest *)request response:(AMapRouteSearchResponse *)response { [self performBlockWithRequest:request withResponse:response]; } - (void)onInputTipsSearchDone:(AMapInputTipsSearchRequest *)request response:(AMapInputTipsSearchResponse *)response { [self performBlockWithRequest:request withResponse:response]; } - (void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response { [self performBlockWithRequest:request withResponse:response]; } - (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response { [self performBlockWithRequest:request withResponse:response]; } @end ================================================ FILE: TripDemo/DDSearchViewController.h ================================================ // // DDSearchViewController.h // TripDemo // // Created by xiaoming han on 15/4/3. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import @class DDLocation; @class DDSearchViewController; @protocol DDSearchViewControllerDelegate @optional - (void)searchViewController:(DDSearchViewController *)searchViewController didSelectLocation:(DDLocation *)location; @end /** * 搜索地点的视图控制器。使用UISearchBar,对关键字进行搜索,得到相关POI信息。 */ @interface DDSearchViewController : UIViewController @property (nonatomic, assign) id delegate; @property (nonatomic, copy) NSString *text; @property (nonatomic, copy) NSString *city; @end ================================================ FILE: TripDemo/DDSearchViewController.m ================================================ // // DDSearchViewController.m // TripDemo // // Created by xiaoming han on 15/4/3. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import "DDSearchViewController.h" #import "DDLocation.h" #import "DDSearchManager.h" @interface DDSearchViewController () @property (nonatomic, strong) UISearchBar *searchBar; @property (nonatomic, strong) UISearchDisplayController *displayController; @property (nonatomic, strong) NSMutableArray *locations; @end @implementation DDSearchViewController - (instancetype)init { self = [super init]; if (self) { _text = @""; _city = @""; _locations = [NSMutableArray array]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; [self initSearchBar]; [self initSearchDisplay]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [_searchBar becomeFirstResponder]; if (self.text.length > 0) { [self searchTipsWithKey:self.text]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { NSLog(@"%s", __func__); } #pragma mark - Initialization - (void)initSearchBar { self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 44)]; self.searchBar.barStyle = UIBarStyleBlack; self.searchBar.translucent = YES; self.searchBar.delegate = self; self.searchBar.placeholder = @"搜索"; self.searchBar.text = self.text; self.searchBar.keyboardType = UIKeyboardTypeDefault; self.navigationItem.titleView = self.searchBar; } - (void)initSearchDisplay { self.displayController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self]; self.displayController.delegate = self; self.displayController.searchResultsDataSource = self; self.displayController.searchResultsDelegate = self; self.displayController.displaysSearchBarInNavigationBar = YES; } #pragma mark - Helpers - (void)searchTipsWithKey:(NSString *)key { if (key.length == 0) { return; } AMapPOIKeywordsSearchRequest *request = [[AMapPOIKeywordsSearchRequest alloc] init]; request.requireExtension = YES; request.keywords = key; if (self.city.length > 0) { request.city = self.city; } __weak __typeof(&*self) weakSelf = self; [[DDSearchManager sharedInstance] searchForRequest:request completionBlock:^(id request, id response, NSError *error) { if (error) { NSLog(@"error :%@", error); } else { [weakSelf.locations removeAllObjects]; AMapPOISearchResponse *aResponse = (AMapPOISearchResponse *)response; [aResponse.pois enumerateObjectsUsingBlock:^(AMapPOI *obj, NSUInteger idx, BOOL *stop) { DDLocation *location = [[DDLocation alloc] init]; location.name = obj.name; location.coordinate = CLLocationCoordinate2DMake(obj.location.latitude, obj.location.longitude); location.address = obj.address; location.cityCode = obj.citycode; [weakSelf.locations addObject:location]; }]; [weakSelf.displayController.searchResultsTableView reloadData]; } }]; } #pragma mark - UISearchBarDelegate - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { self.text = searchBar.text; [self searchTipsWithKey:self.text]; } #pragma mark - UISearchDisplayDelegate - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { self.text = searchString; [self searchTipsWithKey:self.text]; return YES; } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.locations.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"cellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; } DDLocation *location = self.locations[indexPath.row]; cell.textLabel.text = location.name; cell.detailTextLabel.text = location.address; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [_searchBar resignFirstResponder]; [tableView deselectRowAtIndexPath:indexPath animated:NO]; DDLocation *location = self.locations[indexPath.row]; if (_delegate && [_delegate respondsToSelector:@selector(searchViewController:didSelectLocation:)]) { [_delegate searchViewController:self didSelectLocation:location]; } } @end ================================================ FILE: TripDemo/DDTaxiCallRequest.h ================================================ // // TaxiCallingRequest.h // TripDemo // // Created by yi chen on 4/3/15. // Copyright (c) 2015 AutoNavi. All rights reserved. // #import #import "DDLocation.h" /** * 用车请求对象。 */ @interface DDTaxiCallRequest : NSObject @property (nonatomic, strong) DDLocation * start; @property (nonatomic, strong) DDLocation * end; @property (nonatomic, strong) NSString * info; + (instancetype)requestFrom:(DDLocation *)start to:(DDLocation *)end; - (id)initWithStart:(DDLocation *)start to:(DDLocation *)end; @end ================================================ FILE: TripDemo/DDTaxiCallRequest.m ================================================ // // TaxiCallingRequest.m // TripDemo // // Created by yi chen on 4/3/15. // Copyright (c) 2015 AutoNavi. All rights reserved. // #import "DDTaxiCallRequest.h" @implementation DDTaxiCallRequest + (instancetype)requestFrom:(DDLocation *)start to:(DDLocation *)end { return [[self alloc] initWithStart:start to:end]; } - (id)initWithStart:(DDLocation *)start to:(DDLocation *)end { if (self = [super init]) { self.start = start; self.end = end; } return self; } @end ================================================ FILE: TripDemo/Images.xcassets/AppIcon.appiconset/Contents.json ================================================ { "images" : [ { "idiom" : "iphone", "size" : "29x29", "scale" : "2x" }, { "idiom" : "iphone", "size" : "29x29", "scale" : "3x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "2x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "3x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "2x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: TripDemo/Images.xcassets/LaunchImage.launchimage/Contents.json ================================================ { "images" : [ { "orientation" : "portrait", "idiom" : "iphone", "minimum-system-version" : "7.0", "scale" : "2x" }, { "orientation" : "portrait", "idiom" : "iphone", "minimum-system-version" : "7.0", "subtype" : "retina4", "scale" : "2x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: TripDemo/Info.plist ================================================ NSAppTransportSecurity NSAllowsArbitraryLoads CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1 LSRequiresIPhoneOS NSAppTransportSecurity NSAllowsArbitraryLoads NSLocationAlwaysUsageDescription UILaunchStoryboardName Launch Screen UIMainStoryboardFile Main UIRequiredDeviceCapabilities armv7 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait ================================================ FILE: TripDemo/Launch Screen.xib ================================================ ================================================ FILE: TripDemo/MANaviRoute.h ================================================ // // MANaviRoute.h // OfficialDemo3D // // Created by yi chen on 1/7/15. // Copyright (c) 2015 songjian. All rights reserved. // #import #import #import @interface MANaviRoute : NSObject @property (nonatomic, strong) NSArray * path; + (instancetype)naviRouteForPath:(AMapPath *)path; - (id)initWithPath:(AMapPath *)path; @end ================================================ FILE: TripDemo/MANaviRoute.m ================================================ // // MANaviRoute.m // OfficialDemo3D // // Created by yi chen on 1/7/15. // Copyright (c) 2015 songjian. All rights reserved. // #import "MANaviRoute.h" #import "CommonUtility.h" @implementation MANaviRoute #pragma mark - Format Search Result /* polyline parsed from search result. */ + (NSArray *)pathForStep:(AMapStep *)step { if (step == nil) { return nil; } return [CommonUtility pathForCoordinateString:step.polyline]; } #pragma mark - Life Cycle + (instancetype)naviRouteForPath:(AMapPath *)path { return [[self alloc] initWithPath:path]; } - (id)initWithPath:(AMapPath *)path { self = [self init]; if (self == nil) { return nil; } if (path == nil || path.steps.count == 0) { return self; } NSMutableArray *temp_path = [NSMutableArray array]; [path.steps enumerateObjectsUsingBlock:^(AMapStep *step, NSUInteger idx, BOOL *stop) { NSArray *stepPath = [MANaviRoute pathForStep:step]; if (stepPath != nil) { [temp_path addObject:stepPath]; } }]; self.path = temp_path; return self; } @end ================================================ FILE: TripDemo/MovingAnnotation/CACoordLayer.h ================================================ // // CACoordLayer.h // test // // Created by yi chen on 14-9-3. // Copyright (c) 2014年 yi chen. All rights reserved. // #import @interface CACoordLayer : CALayer @property (nonatomic, assign) MAMapView * mapView; @property (nonatomic) double mapx; @property (nonatomic) double mapy; @property (nonatomic) CGPoint centerOffset; @end @interface MAMapView(Additional) - (CGPoint)pointForMapPoint:(MAMapPoint)mapPoint; @end ================================================ FILE: TripDemo/MovingAnnotation/CACoordLayer.m ================================================ // // CACoordLayer.m // test // // Created by yi chen on 14-9-3. // Copyright (c) 2014年 yi chen. All rights reserved. // #import "CACoordLayer.h" @implementation CACoordLayer @dynamic mapx; @dynamic mapy; - (id)initWithLayer:(id)layer { if ((self = [super initWithLayer:layer])) { if ([layer isKindOfClass:[CACoordLayer class]]) { CACoordLayer * input = layer; self.mapx = input.mapx; self.mapy = input.mapy; [self setNeedsDisplay]; } } return self; } + (BOOL)needsDisplayForKey:(NSString *)key { if ([@"mapx" isEqualToString:key]) { return YES; } if ([@"mapy" isEqualToString:key]) { return YES; } return [super needsDisplayForKey:key]; } - (void)display { CACoordLayer * layer = [self presentationLayer]; MAMapPoint mappoint = MAMapPointMake(layer.mapx, layer.mapy); CGPoint center = [self.mapView pointForMapPoint:mappoint]; center.x += self.centerOffset.x; center.y += self.centerOffset.y; self.position = center; } @end ================================================ FILE: TripDemo/MovingAnnotation/MovingAnnotationView.h ================================================ // // MovingAnnotationView.h // test // // Created by yi chen on 14-9-3. // Copyright (c) 2014年 yi chen. All rights reserved. // #import /** * 可以在路径上进行移动动画的annoationView。 */ @interface MovingAnnotationView : MAAnnotationView - (void)addTrackingAnimationForCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count duration:(CFTimeInterval)duration; @end ================================================ FILE: TripDemo/MovingAnnotation/MovingAnnotationView.m ================================================ // // MovingAnnotationView.m // test // // Created by yi chen on 14-9-3. // Copyright (c) 2014年 yi chen. All rights reserved. // #import "MovingAnnotationView.h" #import "CACoordLayer.h" #define MapXAnimationKey @"mapx" #define MapYAnimationKey @"mapy" @interface MovingAnnotationView() @property (nonatomic, strong) NSMutableArray * animationList; @end @implementation MovingAnnotationView { MAMapPoint currDestination; MAMapPoint lastDestination; BOOL isAnimatingX, isAnimatingY; } #pragma mark - Animation + (Class)layerClass { return [CACoordLayer class]; } - (void)addTrackingAnimationForCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count duration:(CFTimeInterval)duration { CACoordLayer * mylayer = ((CACoordLayer *)self.layer); //preparing NSUInteger num = count + 1; NSMutableArray * xvalues = [NSMutableArray arrayWithCapacity:num]; NSMutableArray *yvalues = [NSMutableArray arrayWithCapacity:num]; NSMutableArray * times = [NSMutableArray arrayWithCapacity:num]; double sumOfDistance = 0.f; double * dis = malloc((count) * sizeof(double)); //the first point is set by destination of last animation. MAMapPoint pre; if ([self.animationList count] > 0 || isAnimatingX || isAnimatingY) { pre = MAMapPointMake(lastDestination.x, lastDestination.y); } else { pre = MAMapPointMake(mylayer.mapx, mylayer.mapy); } [xvalues addObject:@(pre.x)]; [yvalues addObject:@(pre.y)]; [times addObject:@(0.f)]; //set the animation points. for (int i = 0; i)annotation reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]; if (self) { CACoordLayer * mylayer = ((CACoordLayer *)self.layer); MAMapPoint mapPoint = MAMapPointForCoordinate(annotation.coordinate); mylayer.mapx = mapPoint.x; mylayer.mapy = mapPoint.y; mylayer.centerOffset = self.centerOffset; isAnimatingX = NO; isAnimatingY = NO; } return self; } @end ================================================ FILE: TripDemo/Toast+UIView.h ================================================ /*************************************************************************** Toast+UIView.h Toast Version 2.0 Copyright (c) 2013 Charles Scalesse. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ #import #import @interface UIView (Toast) // each makeToast method creates a view and displays it as toast - (void)makeToast:(NSString *)message; - (void)makeToast:(NSString *)message duration:(CGFloat)interval position:(id)position; - (void)makeToast:(NSString *)message duration:(CGFloat)interval position:(id)position title:(NSString *)title; - (void)makeToast:(NSString *)message duration:(CGFloat)interval position:(id)position title:(NSString *)title image:(UIImage *)image; - (void)makeToast:(NSString *)message duration:(CGFloat)interval position:(id)position image:(UIImage *)image; // displays toast with an activity spinner - (void)makeToastActivity; - (void)makeToastActivity:(id)position; - (void)hideToastActivity; // the showToast methods display any view as toast - (void)showToast:(UIView *)toast; - (void)showToast:(UIView *)toast duration:(CGFloat)interval position:(id)point; - (UIView *)viewForMessage:(NSString *)message title:(NSString *)title image:(UIImage *)image; - (CGPoint)centerPointForPosition:(id)point withToast:(UIView *)toast; @end ================================================ FILE: TripDemo/Toast+UIView.m ================================================ // // Toast+UIView.m // Toast // Version 2.0 // // Copyright 2013 Charles Scalesse. // #import "Toast+UIView.h" #import #import /* * CONFIGURE THESE VALUES TO ADJUST LOOK & FEEL, * DISPLAY DURATION, ETC. */ // general appearance static const CGFloat CSToastMaxWidth = 0.8; // 80% of parent view width static const CGFloat CSToastMaxHeight = 0.8; // 80% of parent view height static const CGFloat CSToastHorizontalPadding = 10.0; static const CGFloat CSToastVerticalPadding = 10.0; static const CGFloat CSToastCornerRadius = 10.0; static const CGFloat CSToastOpacity = 0.8; static const CGFloat CSToastFontSize = 16.0; static const CGFloat CSToastMaxTitleLines = 0; static const CGFloat CSToastMaxMessageLines = 0; static const CGFloat CSToastFadeDuration = 0.2; // shadow appearance static const CGFloat CSToastShadowOpacity = 0.8; static const CGFloat CSToastShadowRadius = 6.0; static const CGSize CSToastShadowOffset = { 4.0, 4.0 }; static const BOOL CSToastDisplayShadow = YES; // display duration and position static const CGFloat CSToastDefaultDuration = 3.0; static const NSString * CSToastDefaultPosition = @"bottom"; // image view size static const CGFloat CSToastImageViewWidth = 80.0; static const CGFloat CSToastImageViewHeight = 80.0; // activity static const CGFloat CSToastActivityWidth = 100.0; static const CGFloat CSToastActivityHeight = 100.0; static const NSString * CSToastActivityDefaultPosition = @"center"; static const NSString * CSToastActivityViewKey = @"CSToastActivityViewKey"; @interface UIView (ToastPrivate) - (CGPoint)centerPointForPosition:(id)position withToast:(UIView *)toast; - (UIView *)viewForMessage:(NSString *)message title:(NSString *)title image:(UIImage *)image; @end @implementation UIView (Toast) #pragma mark - Toast Methods - (void)makeToast:(NSString *)message { [self makeToast:message duration:CSToastDefaultDuration position:CSToastDefaultPosition]; } - (void)makeToast:(NSString *)message duration:(CGFloat)interval position:(id)position { UIView *toast = [self viewForMessage:message title:nil image:nil]; [self showToast:toast duration:interval position:position]; } - (void)makeToast:(NSString *)message duration:(CGFloat)interval position:(id)position title:(NSString *)title { UIView *toast = [self viewForMessage:message title:title image:nil]; [self showToast:toast duration:interval position:position]; } - (void)makeToast:(NSString *)message duration:(CGFloat)interval position:(id)position image:(UIImage *)image { UIView *toast = [self viewForMessage:message title:nil image:image]; [self showToast:toast duration:interval position:position]; } - (void)makeToast:(NSString *)message duration:(CGFloat)interval position:(id)position title:(NSString *)title image:(UIImage *)image { UIView *toast = [self viewForMessage:message title:title image:image]; [self showToast:toast duration:interval position:position]; } - (void)showToast:(UIView *)toast { [self showToast:toast duration:CSToastDefaultDuration position:CSToastDefaultPosition]; } - (void)showToast:(UIView *)toast duration:(CGFloat)interval position:(id)point { toast.center = [self centerPointForPosition:point withToast:toast]; toast.alpha = 0.0; [self addSubview:toast]; [UIView animateWithDuration:CSToastFadeDuration delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ toast.alpha = 1.0; } completion:^(BOOL finished) { [UIView animateWithDuration:CSToastFadeDuration delay:interval options:UIViewAnimationOptionCurveEaseIn animations:^{ toast.alpha = 0.0; } completion:^(BOOL finished) { [toast removeFromSuperview]; }]; }]; } #pragma mark - Toast Activity Methods - (void)makeToastActivity { [self makeToastActivity:CSToastActivityDefaultPosition]; } - (void)makeToastActivity:(id)position { // sanity UIView *existingActivityView = (UIView *)objc_getAssociatedObject(self, &CSToastActivityViewKey); if (existingActivityView != nil) return; UIView *activityView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, CSToastActivityWidth, CSToastActivityHeight)] autorelease]; activityView.center = [self centerPointForPosition:position withToast:activityView]; activityView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:CSToastOpacity]; activityView.alpha = 0.0; activityView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin); activityView.layer.cornerRadius = CSToastCornerRadius; if (CSToastDisplayShadow) { activityView.layer.shadowColor = [UIColor blackColor].CGColor; activityView.layer.shadowOpacity = CSToastShadowOpacity; activityView.layer.shadowRadius = CSToastShadowRadius; activityView.layer.shadowOffset = CSToastShadowOffset; } UIActivityIndicatorView *activityIndicatorView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease]; activityIndicatorView.center = CGPointMake(activityView.bounds.size.width / 2, activityView.bounds.size.height / 2); [activityView addSubview:activityIndicatorView]; [activityIndicatorView startAnimating]; // associate ourselves with the activity view objc_setAssociatedObject (self, &CSToastActivityViewKey, activityView, OBJC_ASSOCIATION_RETAIN_NONATOMIC); [self addSubview:activityView]; [UIView animateWithDuration:CSToastFadeDuration delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ activityView.alpha = 1.0; } completion:nil]; } - (void)hideToastActivity { UIView *existingActivityView = (UIView *)objc_getAssociatedObject(self, &CSToastActivityViewKey); if (existingActivityView != nil) { [UIView animateWithDuration:CSToastFadeDuration delay:0.0 options:(UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState) animations:^{ existingActivityView.alpha = 0.0; } completion:^(BOOL finished) { [existingActivityView removeFromSuperview]; objc_setAssociatedObject (self, &CSToastActivityViewKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); }]; } } #pragma mark - Private Methods - (CGPoint)centerPointForPosition:(id)point withToast:(UIView *)toast { if([point isKindOfClass:[NSString class]]) { // convert string literals @"top", @"bottom", @"center", or any point wrapped in an NSValue object into a CGPoint if([point caseInsensitiveCompare:@"top"] == NSOrderedSame) { return CGPointMake(self.bounds.size.width/2, (toast.frame.size.height / 2) + CSToastVerticalPadding); } else if([point caseInsensitiveCompare:@"bottom"] == NSOrderedSame) { return CGPointMake(self.bounds.size.width/2, (self.bounds.size.height - (toast.frame.size.height / 2)) - CSToastVerticalPadding); } else if([point caseInsensitiveCompare:@"center"] == NSOrderedSame) { return CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2); } } else if ([point isKindOfClass:[NSValue class]]) { return [point CGPointValue]; } NSLog(@"Warning: Invalid position for toast."); return [self centerPointForPosition:CSToastDefaultPosition withToast:toast]; } - (UIView *)viewForMessage:(NSString *)message title:(NSString *)title image:(UIImage *)image { // sanity if((message == nil) && (title == nil) && (image == nil)) return nil; // dynamically build a toast view with any combination of message, title, & image. UILabel *messageLabel = nil; UILabel *titleLabel = nil; UIImageView *imageView = nil; // create the parent view UIView *wrapperView = [[[UIView alloc] init] autorelease]; wrapperView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin); wrapperView.layer.cornerRadius = CSToastCornerRadius; if (CSToastDisplayShadow) { wrapperView.layer.shadowColor = [UIColor blackColor].CGColor; wrapperView.layer.shadowOpacity = CSToastShadowOpacity; wrapperView.layer.shadowRadius = CSToastShadowRadius; wrapperView.layer.shadowOffset = CSToastShadowOffset; } wrapperView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:CSToastOpacity]; if(image != nil) { imageView = [[[UIImageView alloc] initWithImage:image] autorelease]; imageView.contentMode = UIViewContentModeScaleAspectFit; imageView.frame = CGRectMake(CSToastHorizontalPadding, CSToastVerticalPadding, CSToastImageViewWidth, CSToastImageViewHeight); } CGFloat imageWidth, imageHeight, imageLeft; // the imageView frame values will be used to size & position the other views if(imageView != nil) { imageWidth = imageView.bounds.size.width; imageHeight = imageView.bounds.size.height; imageLeft = CSToastHorizontalPadding; } else { imageWidth = imageHeight = imageLeft = 0.0; } if (title != nil) { titleLabel = [[[UILabel alloc] init] autorelease]; titleLabel.numberOfLines = CSToastMaxTitleLines; titleLabel.font = [UIFont boldSystemFontOfSize:CSToastFontSize]; titleLabel.textAlignment = NSTextAlignmentLeft; titleLabel.lineBreakMode = NSLineBreakByWordWrapping; titleLabel.textColor = [UIColor whiteColor]; titleLabel.backgroundColor = [UIColor clearColor]; titleLabel.alpha = 1.0; titleLabel.text = title; // size the title label according to the length of the text CGSize maxSizeTitle = CGSizeMake((self.bounds.size.width * CSToastMaxWidth) - imageWidth, self.bounds.size.height * CSToastMaxHeight); CGSize expectedSizeTitle = [title sizeWithFont:titleLabel.font constrainedToSize:maxSizeTitle lineBreakMode:titleLabel.lineBreakMode]; titleLabel.frame = CGRectMake(0.0, 0.0, expectedSizeTitle.width, expectedSizeTitle.height); } if (message != nil) { messageLabel = [[[UILabel alloc] init] autorelease]; messageLabel.numberOfLines = CSToastMaxMessageLines; messageLabel.font = [UIFont systemFontOfSize:CSToastFontSize]; messageLabel.lineBreakMode = NSLineBreakByWordWrapping; messageLabel.textColor = [UIColor whiteColor]; messageLabel.backgroundColor = [UIColor clearColor]; messageLabel.alpha = 1.0; messageLabel.text = message; // size the message label according to the length of the text CGSize maxSizeMessage = CGSizeMake((self.bounds.size.width * CSToastMaxWidth) - imageWidth, self.bounds.size.height * CSToastMaxHeight); CGSize expectedSizeMessage = [message sizeWithFont:messageLabel.font constrainedToSize:maxSizeMessage lineBreakMode:messageLabel.lineBreakMode]; messageLabel.frame = CGRectMake(0.0, 0.0, expectedSizeMessage.width, expectedSizeMessage.height); } // titleLabel frame values CGFloat titleWidth, titleHeight, titleTop, titleLeft; if(titleLabel != nil) { titleWidth = titleLabel.bounds.size.width; titleHeight = titleLabel.bounds.size.height; titleTop = CSToastVerticalPadding; titleLeft = imageLeft + imageWidth + CSToastHorizontalPadding; } else { titleWidth = titleHeight = titleTop = titleLeft = 0.0; } // messageLabel frame values CGFloat messageWidth, messageHeight, messageLeft, messageTop; if(messageLabel != nil) { messageWidth = messageLabel.bounds.size.width; messageHeight = messageLabel.bounds.size.height; messageLeft = imageLeft + imageWidth + CSToastHorizontalPadding; messageTop = titleTop + titleHeight + CSToastVerticalPadding; } else { messageWidth = messageHeight = messageLeft = messageTop = 0.0; } CGFloat longerWidth = MAX(titleWidth, messageWidth); CGFloat longerLeft = MAX(titleLeft, messageLeft); // wrapper width uses the longerWidth or the image width, whatever is larger. same logic applies to the wrapper height CGFloat wrapperWidth = MAX((imageWidth + (CSToastHorizontalPadding * 2)), (longerLeft + longerWidth + CSToastHorizontalPadding)); CGFloat wrapperHeight = MAX((messageTop + messageHeight + CSToastVerticalPadding), (imageHeight + (CSToastVerticalPadding * 2))); wrapperView.frame = CGRectMake(0.0, 0.0, wrapperWidth, wrapperHeight); if(titleLabel != nil) { titleLabel.frame = CGRectMake(titleLeft, titleTop, titleWidth, titleHeight); [wrapperView addSubview:titleLabel]; } if(messageLabel != nil) { messageLabel.frame = CGRectMake(messageLeft, messageTop, messageWidth, messageHeight); [wrapperView addSubview:messageLabel]; } if(imageView != nil) { [wrapperView addSubview:imageView]; } return wrapperView; } @end ================================================ FILE: TripDemo/ViewController.h ================================================ // // ViewController.h // TripDemo // // Created by xiaoming han on 15/4/2. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import @interface ViewController : UIViewController @end ================================================ FILE: TripDemo/ViewController.m ================================================ // // ViewController.m // TripDemo // // Created by xiaoming han on 15/4/2. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import "ViewController.h" #import #import #import "DDLocation.h" #import "DDSearchViewController.h" #import "DDSearchManager.h" #import "DDDriverManager.h" #import "DDLocationView.h" #import "Toast+UIView.h" #import "MovingAnnotationView.h" typedef NS_ENUM(NSUInteger, DDState) { DDState_Init = 0, //初始状态,显示选择终点 DDState_Confirm_Destination, //选定起始点和目的地,显示马上叫车 DDState_Call_Taxi, //正在叫车,显示我已上车 DDState_On_Taxi, //正在车上状态,显示支付 DDState_Finish_pay //到达终点,显示评价 }; #define kLocationViewMargin 20 #define kButtonMargin 20 #define kButtonHeight 40 #define kAppName @"德德用车" @interface ViewController () { MAMapView *_mapView; UIView * _messageView; DDDriverManager * _driverManager; NSArray * _drivers; MAPointAnnotation * _selectedDriver; UIButton *_buttonAction; UIButton *_buttonCancel; UIButton *_buttonLocating; int _currentSearchLocation; //0 start, 1 end BOOL _needsFirstLocating; } @property (nonatomic, strong) DDLocation * currentLocation; @property (nonatomic, strong) DDLocation * destinationLocation; @property (nonatomic, assign) DDState state; @property (nonatomic, strong) DDLocationView *locationView; @property (nonatomic, assign) BOOL isLocating; @end @implementation ViewController #pragma mark - search - (void)searchReGeocodeWithCoordinate:(CLLocationCoordinate2D)coordinate { AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init]; regeo.location = [AMapGeoPoint locationWithLatitude:coordinate.latitude longitude:coordinate.longitude]; regeo.requireExtension = YES; __weak __typeof(&*self) weakSelf = self; [[DDSearchManager sharedInstance] searchForRequest:regeo completionBlock:^(id request, id response, NSError *error) { if (error) { NSLog(@"error :%@", error); } else { AMapReGeocodeSearchResponse * regeoResponse = response; if (regeoResponse.regeocode != nil) { if (regeoResponse.regeocode.pois.count > 0) { AMapPOI *poi = regeoResponse.regeocode.pois[0]; weakSelf.currentLocation.coordinate = CLLocationCoordinate2DMake(poi.location.latitude, poi.location.longitude); weakSelf.currentLocation.name = poi.name; weakSelf.currentLocation.address = poi.address; } else { weakSelf.currentLocation.coordinate = CLLocationCoordinate2DMake(regeoResponse.regeocode.addressComponent.streetNumber.location.latitude, regeoResponse.regeocode.addressComponent.streetNumber.location.longitude); weakSelf.currentLocation.name = [NSString stringWithFormat:@"%@%@%@%@%@", regeoResponse.regeocode.addressComponent.township, regeoResponse.regeocode.addressComponent.neighborhood, regeoResponse.regeocode.addressComponent.streetNumber.street, regeoResponse.regeocode.addressComponent.streetNumber.number, regeoResponse.regeocode.addressComponent.building]; weakSelf.currentLocation.address = regeoResponse.regeocode.formattedAddress; } weakSelf.currentLocation.cityCode = regeoResponse.regeocode.addressComponent.citycode; weakSelf.isLocating = NO; NSLog(@"currentLocation:%@", weakSelf.currentLocation); } } }]; } #pragma mark - mapView delegate - (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation { if (_needsFirstLocating && updatingLocation) { [self actionLocating:nil]; _needsFirstLocating = NO; } } - (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation { /* 自定义userLocation对应的annotationView. */ if ([annotation isKindOfClass:[MAUserLocation class]]) { static NSString *userLocationStyleReuseIndetifier = @"userLocationReuseIndetifier"; MAAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:userLocationStyleReuseIndetifier]; if (annotationView == nil) { annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:userLocationStyleReuseIndetifier]; } UIImage *image = [UIImage imageNamed:@"icon_passenger"]; annotationView.image = image; annotationView.centerOffset = CGPointMake(0, -22); annotationView.canShowCallout = YES; return annotationView; } if ([annotation isKindOfClass:[MAPointAnnotation class]]) { static NSString *pointReuseIndetifier = @"driverReuseIndetifier"; MovingAnnotationView *annotationView = (MovingAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier]; if (annotationView == nil) { annotationView = [[MovingAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier]; } UIImage *image = [UIImage imageNamed:@"icon_taxi"]; annotationView.image = image; annotationView.centerOffset = CGPointMake(0, -22); annotationView.canShowCallout = YES; return annotationView; } return nil; } #pragma mark - life cycle - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.title = kAppName; self.edgesForExtendedLayout = UIRectEdgeNone; _needsFirstLocating = YES; _isLocating = NO; _currentSearchLocation = -1; _mapView = [[MAMapView alloc] initWithFrame:self.view.bounds]; _mapView.showsIndoorMap = NO; _mapView.showsCompass = NO; _mapView.rotateEnabled = NO; _mapView.showsScale = NO; // 去除精度圈。 _mapView.customizeUserLocationAccuracyCircleRepresentation = YES; [self.view addSubview:_mapView]; _driverManager = [[DDDriverManager alloc] init]; _driverManager.delegate = self; // controls _buttonAction = [UIButton buttonWithType:UIButtonTypeCustom]; _buttonAction.backgroundColor = [UIColor colorWithRed:13.0/255.0 green:79.0/255.0 blue:139.0/255.0 alpha:1.0]; _buttonAction.layer.cornerRadius = 6; _buttonAction.layer.shadowColor = [UIColor blackColor].CGColor; _buttonAction.layer.shadowOffset = CGSizeMake(1, 1); _buttonAction.layer.shadowOpacity = 0.5; [self.view addSubview:_buttonAction]; _buttonCancel = [UIButton buttonWithType:UIButtonTypeCustom]; _buttonCancel.backgroundColor = [UIColor colorWithWhite:0.25 alpha:1.0]; _buttonCancel.layer.cornerRadius = 6; _buttonCancel.layer.shadowColor = [UIColor blackColor].CGColor; _buttonCancel.layer.shadowOffset = CGSizeMake(1, 1); _buttonCancel.layer.shadowOpacity = 0.5; [_buttonCancel setTitle:@"取消" forState:UIControlStateNormal]; [_buttonCancel addTarget:self action:@selector(actionCancel:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_buttonCancel]; _buttonLocating = [UIButton buttonWithType:UIButtonTypeCustom]; [_buttonLocating setImage:[UIImage imageNamed:@"location"] forState:UIControlStateNormal]; _buttonLocating.backgroundColor = [UIColor whiteColor]; _buttonLocating.layer.cornerRadius = 6; _buttonLocating.layer.shadowColor = [UIColor blackColor].CGColor; _buttonLocating.layer.shadowOffset = CGSizeMake(1, 1); _buttonLocating.layer.shadowOpacity = 0.5; [_buttonLocating addTarget:self action:@selector(actionLocating:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_buttonLocating]; _currentLocation = [[DDLocation alloc] init]; _locationView = [[DDLocationView alloc] initWithFrame:CGRectMake(kLocationViewMargin, kLocationViewMargin, CGRectGetWidth(self.view.bounds) - kLocationViewMargin * 2, 44)]; _locationView.delegate = self; _locationView.startLocation = _currentLocation; [self.view addSubview:_locationView]; [self setState:DDState_Init]; } - (void)viewDidAppear:(BOOL)animated { _mapView.delegate = self; _mapView.showsUserLocation = YES; } - (void)viewWillDisappear:(BOOL)animated { _mapView.showsUserLocation = NO; _mapView.delegate = nil; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)viewDidLayoutSubviews { _mapView.frame = self.view.bounds; _buttonCancel.frame = CGRectMake(kButtonMargin, CGRectGetHeight(self.view.bounds) - kButtonMargin - kButtonHeight, CGRectGetMaxX(self.view.bounds) - kButtonMargin * 2, kButtonHeight); _buttonAction.frame = CGRectMake(kButtonMargin, CGRectGetMinY(_buttonCancel.frame) - kButtonMargin / 2.0 - kButtonHeight, CGRectGetMaxX(self.view.bounds) - kButtonMargin * 2, kButtonHeight); _buttonLocating.frame = CGRectMake(kButtonMargin, CGRectGetMinY(_buttonAction.frame) - kButtonMargin - kButtonHeight, kButtonHeight, kButtonHeight); } #pragma mark - Action - (void)actionAddEnd:(UIButton *)sender { NSLog(@"actionAddEnd"); if (_currentLocation.cityCode.length == 0) { NSLog(@"the city have not been located"); return; } _currentSearchLocation = 1; DDSearchViewController *searchController = [[DDSearchViewController alloc] init]; searchController.delegate = self; searchController.city = _currentLocation.cityCode; [self.navigationController pushViewController:searchController animated:YES]; } - (void)actionCancel:(UIButton *)sender { NSLog(@"actionCancel"); [self setState:DDState_Init]; } - (void)actionCallTaxi:(UIButton *)sender { NSLog(@"actionCallTaxi"); if (self.currentLocation && self.destinationLocation) { DDTaxiCallRequest * request = [[DDTaxiCallRequest alloc] initWithStart:self.currentLocation to:self.destinationLocation]; [_driverManager callTaxiWithRequest:request]; _messageView = [_mapView viewForMessage:@"正在呼叫司机..." title:nil image:nil]; _messageView.center = [_mapView centerPointForPosition:@"center" withToast:_messageView]; [_mapView addSubview:_messageView]; } } - (void)actionLocating:(UIButton *)sender { NSLog(@"actionLocating"); // 只有初始状态下才可以进行定位。 if (_state != DDState_Init) { [self.view makeToast:@"重新请求需先取消用车" duration:1.0 position:@"center"]; return; } if (!_isLocating) { _isLocating = YES; [self resetMapToCenter:_mapView.userLocation.location.coordinate]; [self searchReGeocodeWithCoordinate:_mapView.userLocation.location.coordinate]; [self updatingDrivers]; } } - (void)actionOnTaxi:(UIButton *)sender { NSLog(@"actionOnTaxi"); [self setState:DDState_On_Taxi]; } - (void)actionOnPay:(UIButton *)sender { NSLog(@"actionOnPay"); [self setState:DDState_Finish_pay]; } - (void)actionOnEvaluate:(UIButton *)sender { NSLog(@"actionOnEvaluate"); [self setState:DDState_Init]; } #pragma mark - drivers - (void)updatingDrivers { #define latitudinalRangeMeters 1000.0 #define longitudinalRangeMeters 1000.0 MAMapRect rect = MAMapRectForCoordinateRegion(MACoordinateRegionMakeWithDistance(_mapView.centerCoordinate, latitudinalRangeMeters, longitudinalRangeMeters)); [_driverManager searchDriversWithinMapRect:rect]; } #pragma mark - driversManager delegate - (void)searchDoneInMapRect:(MAMapRect)mapRect withDriversResult:(NSArray *)drivers timestamp:(NSTimeInterval)timestamp { [_mapView removeAnnotations:_drivers]; NSMutableArray * currDrivers = [NSMutableArray arrayWithCapacity:[drivers count]]; [drivers enumerateObjectsUsingBlock:^(DDDriver * obj, NSUInteger idx, BOOL *stop) { MAPointAnnotation * driver = [[MAPointAnnotation alloc] init]; driver.coordinate = obj.coordinate; driver.title = obj.idInfo; [currDrivers addObject:driver]; }]; [_mapView addAnnotations:currDrivers]; _drivers = currDrivers; } - (void)callTaxiDoneWithRequest:(DDTaxiCallRequest *)request Taxi:(DDDriver *)driver { [_mapView removeAnnotations:_drivers]; _selectedDriver = [[MAPointAnnotation alloc] init]; _selectedDriver.coordinate = driver.coordinate; _selectedDriver.title = driver.idInfo; [_mapView addAnnotation:_selectedDriver]; [_messageView removeFromSuperview]; [_mapView makeToast:[NSString stringWithFormat:@"已选择司机%@",driver.idInfo, nil] duration:0.5 position:@"center"]; [self setState:DDState_Call_Taxi]; } - (void)onUpdatingLocations:(NSArray *)locations forDriver:(DDDriver *)driver { if ([locations count] > 0) { [_mapView selectAnnotation:_selectedDriver animated:NO]; _selectedDriver.coordinate = ((CLLocation*) [locations lastObject]).coordinate; CLLocationCoordinate2D * locs = (CLLocationCoordinate2D *)malloc(sizeof(CLLocationCoordinate2D) * [locations count]); [locations enumerateObjectsUsingBlock:^(CLLocation * obj, NSUInteger idx, BOOL *stop) { locs[idx] = obj.coordinate; }]; MovingAnnotationView * driverView = (MovingAnnotationView *)[_mapView viewForAnnotation:_selectedDriver]; [driverView addTrackingAnimationForCoordinates:locs count:[locations count] duration:2.0]; free(locs); } } #pragma mark - DDSearchViewControllerDelegate - (void)searchViewController:(DDSearchViewController *)searchViewController didSelectLocation:(DDLocation *)location { NSLog(@"location: %@", location); [self.navigationController popViewControllerAnimated:YES]; if (_currentSearchLocation == 0) { _currentLocation = location; _locationView.startLocation = location; } else if (_currentSearchLocation == 1) { _destinationLocation = location; _locationView.endLocation = location; } _currentSearchLocation = -1; // 起点终点都确认 if (_currentLocation && _destinationLocation) { [self setState:DDState_Confirm_Destination]; } } #pragma mark - Utility - (void)requestPathInfo { //检索所需费用 AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init]; navi.requireExtension = YES; /* 出发点. */ navi.origin = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude]; /* 目的地. */ navi.destination = [AMapGeoPoint locationWithLatitude:_destinationLocation.coordinate.latitude longitude:_destinationLocation.coordinate.longitude]; __weak __typeof(&*self) weakSelf = self; [[DDSearchManager sharedInstance] searchForRequest:navi completionBlock:^(id request, id response, NSError *error) { AMapRouteSearchResponse *naviResponse = response; if (naviResponse.route == nil) { [weakSelf.locationView setInfo:@"获取路径失败"]; return; } AMapPath * path = [naviResponse.route.paths firstObject]; [weakSelf.locationView setInfo:[NSString stringWithFormat:@"预估费用%.2f元 距离%.1f km 时间%.1f分钟", naviResponse.route.taxiCost, path.distance / 1000.f, path.duration / 60.f, nil]]; }]; } - (void)setState:(DDState)state { _state = state; switch (state) { case DDState_Init: [self reset]; [_buttonAction setTitle:@"选择终点" forState:UIControlStateNormal]; [_buttonAction removeTarget:self action:NULL forControlEvents:UIControlEventTouchUpInside]; [_buttonAction addTarget:self action:@selector(actionAddEnd:) forControlEvents:UIControlEventTouchUpInside]; break; case DDState_Confirm_Destination: [self requestPathInfo]; [_buttonAction setTitle:@"马上叫车" forState:UIControlStateNormal]; [_buttonAction removeTarget:self action:NULL forControlEvents:UIControlEventTouchUpInside]; [_buttonAction addTarget:self action:@selector(actionCallTaxi:) forControlEvents:UIControlEventTouchUpInside]; break; case DDState_Call_Taxi: [_buttonAction setTitle:@"我已上车" forState:UIControlStateNormal]; [_buttonAction removeTarget:self action:NULL forControlEvents:UIControlEventTouchUpInside]; [_buttonAction addTarget:self action:@selector(actionOnTaxi:) forControlEvents:UIControlEventTouchUpInside]; break; case DDState_On_Taxi: [_buttonAction setTitle:@"支付" forState:UIControlStateNormal]; [_buttonAction removeTarget:self action:NULL forControlEvents:UIControlEventTouchUpInside]; [_buttonAction addTarget:self action:@selector(actionOnPay:) forControlEvents:UIControlEventTouchUpInside]; break; case DDState_Finish_pay: [_buttonAction setTitle:@"评价" forState:UIControlStateNormal]; [_buttonAction removeTarget:self action:NULL forControlEvents:UIControlEventTouchUpInside]; [_buttonAction addTarget:self action:@selector(actionOnEvaluate:) forControlEvents:UIControlEventTouchUpInside]; break; default: break; } // 设置locationView是否响应交互。 _locationView.userInteractionEnabled = state < DDState_Call_Taxi; _buttonCancel.hidden = state == DDState_Init; } - (void)reset { [_mapView removeAnnotations:_drivers]; [_mapView removeAnnotation:_selectedDriver]; _needsFirstLocating = YES; _destinationLocation = nil; _locationView.endLocation = nil; _locationView.info = nil; } - (void)resetMapToCenter:(CLLocationCoordinate2D)coordinate { _mapView.centerCoordinate = coordinate; _mapView.zoomLevel = 15.1; // 使得userLocationView在最前。 [_mapView selectAnnotation:_mapView.userLocation animated:YES]; } #pragma mark - DDLocationViewDelegate - (void)didClickStartLocation:(DDLocationView *)locationView { _currentSearchLocation = 0; DDSearchViewController *searchController = [[DDSearchViewController alloc] init]; searchController.delegate = self; searchController.text = locationView.startLocation.name; searchController.city = locationView.startLocation.cityCode; [self.navigationController pushViewController:searchController animated:YES]; } - (void)didClickEndLocation:(DDLocationView *)locationView { _currentSearchLocation = 1; DDSearchViewController *searchController = [[DDSearchViewController alloc] init]; searchController.delegate = self; searchController.text = locationView.endLocation.name; searchController.city = locationView.endLocation.cityCode; [self.navigationController pushViewController:searchController animated:YES]; } @end ================================================ FILE: TripDemo/main.m ================================================ // // main.m // TripDemo // // Created by xiaoming han on 15/4/2. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import #import "AppDelegate.h" int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } ================================================ FILE: TripDemo.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ 0BED4973DBD8A848E94AEC49 /* libPods-TripDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E2A7A119D10C912EA2FA028 /* libPods-TripDemo.a */; }; 810379DF1ACD6E0A0013124A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 810379DE1ACD6E0A0013124A /* main.m */; }; 810379E21ACD6E0A0013124A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 810379E11ACD6E0A0013124A /* AppDelegate.m */; }; 810379E51ACD6E0A0013124A /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 810379E41ACD6E0A0013124A /* ViewController.m */; }; 810379E81ACD6E0A0013124A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 810379E61ACD6E0A0013124A /* Main.storyboard */; }; 810379EA1ACD6E0A0013124A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 810379E91ACD6E0A0013124A /* Images.xcassets */; }; 81037A051ACD79CB0013124A /* DDLocationView.m in Sources */ = {isa = PBXBuildFile; fileRef = 81037A041ACD79CB0013124A /* DDLocationView.m */; }; 81037A091ACD7ABA0013124A /* DDLocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 81037A081ACD7ABA0013124A /* DDLocation.m */; }; 81037A0F1ACD7BAE0013124A /* endPoint.png in Resources */ = {isa = PBXBuildFile; fileRef = 81037A0A1ACD7BAE0013124A /* endPoint.png */; }; 81037A101ACD7BAE0013124A /* endPoint@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 81037A0B1ACD7BAE0013124A /* endPoint@2x.png */; }; 81037A121ACD7BAE0013124A /* startPoint.png in Resources */ = {isa = PBXBuildFile; fileRef = 81037A0D1ACD7BAE0013124A /* startPoint.png */; }; 81037A131ACD7BAE0013124A /* startPoint@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 81037A0E1ACD7BAE0013124A /* startPoint@2x.png */; }; 81B5E8D01ACE3E3A00AA7FFE /* DDSearchViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B5E8CF1ACE3E3A00AA7FFE /* DDSearchViewController.m */; }; 81B5E8D31ACE47DE00AA7FFE /* DDSearchManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B5E8D21ACE47DE00AA7FFE /* DDSearchManager.m */; }; 81B5E8D71ACE8B1800AA7FFE /* DDLocationControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B5E8D61ACE8B1800AA7FFE /* DDLocationControl.m */; }; 81B5E8D91ACE949700AA7FFE /* icon_next@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 81B5E8D81ACE949700AA7FFE /* icon_next@2x.png */; }; 81B5E9711AD3CCB200AA7FFE /* Launch Screen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 81B5E9701AD3CCB200AA7FFE /* Launch Screen.xib */; }; 81B5E9A01AD61EF000AA7FFE /* DDDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B5E99D1AD61EF000AA7FFE /* DDDriver.m */; }; 81B5E9A11AD61EF000AA7FFE /* DDTaxiCallRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B5E99F1AD61EF000AA7FFE /* DDTaxiCallRequest.m */; }; 81B5E9A81AD6269400AA7FFE /* icon_passenger@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 81B5E9A71AD6269400AA7FFE /* icon_passenger@2x.png */; }; C81057811ACE49BE00CD0D55 /* DDDriverManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C81057801ACE49BE00CD0D55 /* DDDriverManager.m */; }; C81057891ACE791600CD0D55 /* MANaviRoute.m in Sources */ = {isa = PBXBuildFile; fileRef = C81057881ACE791600CD0D55 /* MANaviRoute.m */; }; C810578D1ACE7A8100CD0D55 /* CommonUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = C810578C1ACE7A8100CD0D55 /* CommonUtility.m */; }; C810578F1ACE959200CD0D55 /* location@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C810578E1ACE959200CD0D55 /* location@2x.png */; }; C81057921AD38CEF00CD0D55 /* Toast+UIView.m in Sources */ = {isa = PBXBuildFile; fileRef = C81057911AD38CEF00CD0D55 /* Toast+UIView.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; C81057991AD390DD00CD0D55 /* CACoordLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = C81057961AD390DD00CD0D55 /* CACoordLayer.m */; }; C810579A1AD390DD00CD0D55 /* MovingAnnotationView.m in Sources */ = {isa = PBXBuildFile; fileRef = C81057981AD390DD00CD0D55 /* MovingAnnotationView.m */; }; C810579C1AD3AE7D00CD0D55 /* icon_taxi@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C810579B1AD3AE7D00CD0D55 /* icon_taxi@2x.png */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 50AB20858F2ADB96B975925F /* Pods-TripDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TripDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-TripDemo/Pods-TripDemo.release.xcconfig"; sourceTree = ""; }; 810379D91ACD6E0A0013124A /* TripDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TripDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 810379DD1ACD6E0A0013124A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 810379DE1ACD6E0A0013124A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 810379E01ACD6E0A0013124A /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 810379E11ACD6E0A0013124A /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 810379E31ACD6E0A0013124A /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 810379E41ACD6E0A0013124A /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 810379E71ACD6E0A0013124A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 810379E91ACD6E0A0013124A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 810379F71ACD6E0A0013124A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 810379F81ACD6E0A0013124A /* TripDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TripDemoTests.m; sourceTree = ""; }; 81037A031ACD79CB0013124A /* DDLocationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDLocationView.h; sourceTree = ""; }; 81037A041ACD79CB0013124A /* DDLocationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDLocationView.m; sourceTree = ""; }; 81037A071ACD7ABA0013124A /* DDLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDLocation.h; sourceTree = ""; }; 81037A081ACD7ABA0013124A /* DDLocation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDLocation.m; sourceTree = ""; }; 81037A0A1ACD7BAE0013124A /* endPoint.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = endPoint.png; sourceTree = ""; }; 81037A0B1ACD7BAE0013124A /* endPoint@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "endPoint@2x.png"; sourceTree = ""; }; 81037A0D1ACD7BAE0013124A /* startPoint.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = startPoint.png; sourceTree = ""; }; 81037A0E1ACD7BAE0013124A /* startPoint@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "startPoint@2x.png"; sourceTree = ""; }; 81B5E8CE1ACE3E3A00AA7FFE /* DDSearchViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDSearchViewController.h; sourceTree = ""; }; 81B5E8CF1ACE3E3A00AA7FFE /* DDSearchViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDSearchViewController.m; sourceTree = ""; }; 81B5E8D11ACE47DE00AA7FFE /* DDSearchManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDSearchManager.h; sourceTree = ""; }; 81B5E8D21ACE47DE00AA7FFE /* DDSearchManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDSearchManager.m; sourceTree = ""; }; 81B5E8D51ACE8B1800AA7FFE /* DDLocationControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDLocationControl.h; sourceTree = ""; }; 81B5E8D61ACE8B1800AA7FFE /* DDLocationControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDLocationControl.m; sourceTree = ""; }; 81B5E8D81ACE949700AA7FFE /* icon_next@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_next@2x.png"; sourceTree = ""; }; 81B5E9701AD3CCB200AA7FFE /* Launch Screen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = "Launch Screen.xib"; sourceTree = ""; }; 81B5E99C1AD61EF000AA7FFE /* DDDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDDriver.h; sourceTree = ""; }; 81B5E99D1AD61EF000AA7FFE /* DDDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDDriver.m; sourceTree = ""; }; 81B5E99E1AD61EF000AA7FFE /* DDTaxiCallRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDTaxiCallRequest.h; sourceTree = ""; }; 81B5E99F1AD61EF000AA7FFE /* DDTaxiCallRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDTaxiCallRequest.m; sourceTree = ""; }; 81B5E9A71AD6269400AA7FFE /* icon_passenger@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_passenger@2x.png"; sourceTree = ""; }; 8E2A7A119D10C912EA2FA028 /* libPods-TripDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-TripDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; C810577F1ACE49BE00CD0D55 /* DDDriverManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDDriverManager.h; sourceTree = ""; }; C81057801ACE49BE00CD0D55 /* DDDriverManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDDriverManager.m; sourceTree = ""; }; C81057881ACE791600CD0D55 /* MANaviRoute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MANaviRoute.m; sourceTree = ""; }; C810578A1ACE792500CD0D55 /* MANaviRoute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MANaviRoute.h; sourceTree = ""; }; C810578B1ACE7A7800CD0D55 /* CommonUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommonUtility.h; sourceTree = ""; }; C810578C1ACE7A8100CD0D55 /* CommonUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommonUtility.m; sourceTree = ""; }; C810578E1ACE959200CD0D55 /* location@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "location@2x.png"; sourceTree = ""; }; C81057901AD38CEF00CD0D55 /* Toast+UIView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Toast+UIView.h"; sourceTree = ""; }; C81057911AD38CEF00CD0D55 /* Toast+UIView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Toast+UIView.m"; sourceTree = ""; }; C81057951AD390DD00CD0D55 /* CACoordLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CACoordLayer.h; sourceTree = ""; }; C81057961AD390DD00CD0D55 /* CACoordLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CACoordLayer.m; sourceTree = ""; }; C81057971AD390DD00CD0D55 /* MovingAnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MovingAnnotationView.h; sourceTree = ""; }; C81057981AD390DD00CD0D55 /* MovingAnnotationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MovingAnnotationView.m; sourceTree = ""; }; C810579B1AD3AE7D00CD0D55 /* icon_taxi@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_taxi@2x.png"; sourceTree = ""; }; E85CDFD9CCB0E2D041F8D094 /* Pods-TripDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TripDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-TripDemo/Pods-TripDemo.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 810379D61ACD6E0A0013124A /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( 0BED4973DBD8A848E94AEC49 /* libPods-TripDemo.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 2609663A5B7725E4F8E9CC54 /* Frameworks */ = { isa = PBXGroup; children = ( 8E2A7A119D10C912EA2FA028 /* libPods-TripDemo.a */, ); name = Frameworks; sourceTree = ""; }; 810379D01ACD6E090013124A = { isa = PBXGroup; children = ( 810379DB1ACD6E0A0013124A /* TripDemo */, 810379F51ACD6E0A0013124A /* TripDemoTests */, 810379DA1ACD6E0A0013124A /* Products */, C12DD25E80D1C4CC38F306F9 /* Pods */, 2609663A5B7725E4F8E9CC54 /* Frameworks */, ); sourceTree = ""; }; 810379DA1ACD6E0A0013124A /* Products */ = { isa = PBXGroup; children = ( 810379D91ACD6E0A0013124A /* TripDemo.app */, ); name = Products; sourceTree = ""; }; 810379DB1ACD6E0A0013124A /* TripDemo */ = { isa = PBXGroup; children = ( 810379E01ACD6E0A0013124A /* AppDelegate.h */, 810379E11ACD6E0A0013124A /* AppDelegate.m */, 810379E31ACD6E0A0013124A /* ViewController.h */, 810379E41ACD6E0A0013124A /* ViewController.m */, 81037A031ACD79CB0013124A /* DDLocationView.h */, 81037A041ACD79CB0013124A /* DDLocationView.m */, 81B5E8D51ACE8B1800AA7FFE /* DDLocationControl.h */, 81B5E8D61ACE8B1800AA7FFE /* DDLocationControl.m */, 81037A071ACD7ABA0013124A /* DDLocation.h */, 81037A081ACD7ABA0013124A /* DDLocation.m */, 81B5E99C1AD61EF000AA7FFE /* DDDriver.h */, 81B5E99D1AD61EF000AA7FFE /* DDDriver.m */, 81B5E99E1AD61EF000AA7FFE /* DDTaxiCallRequest.h */, 81B5E99F1AD61EF000AA7FFE /* DDTaxiCallRequest.m */, C810577F1ACE49BE00CD0D55 /* DDDriverManager.h */, C81057801ACE49BE00CD0D55 /* DDDriverManager.m */, C810578A1ACE792500CD0D55 /* MANaviRoute.h */, C81057881ACE791600CD0D55 /* MANaviRoute.m */, C810578B1ACE7A7800CD0D55 /* CommonUtility.h */, C810578C1ACE7A8100CD0D55 /* CommonUtility.m */, 81B5E8D11ACE47DE00AA7FFE /* DDSearchManager.h */, 81B5E8D21ACE47DE00AA7FFE /* DDSearchManager.m */, 81B5E8CE1ACE3E3A00AA7FFE /* DDSearchViewController.h */, 81B5E8CF1ACE3E3A00AA7FFE /* DDSearchViewController.m */, C81057941AD390DD00CD0D55 /* MovingAnnotation */, C81057901AD38CEF00CD0D55 /* Toast+UIView.h */, C81057911AD38CEF00CD0D55 /* Toast+UIView.m */, C810578E1ACE959200CD0D55 /* location@2x.png */, 81B5E9A71AD6269400AA7FFE /* icon_passenger@2x.png */, 81B5E8D81ACE949700AA7FFE /* icon_next@2x.png */, C810579B1AD3AE7D00CD0D55 /* icon_taxi@2x.png */, 81037A0A1ACD7BAE0013124A /* endPoint.png */, 81037A0B1ACD7BAE0013124A /* endPoint@2x.png */, 81037A0D1ACD7BAE0013124A /* startPoint.png */, 81037A0E1ACD7BAE0013124A /* startPoint@2x.png */, 810379E61ACD6E0A0013124A /* Main.storyboard */, 81B5E9701AD3CCB200AA7FFE /* Launch Screen.xib */, 810379E91ACD6E0A0013124A /* Images.xcassets */, 810379DC1ACD6E0A0013124A /* Supporting Files */, ); path = TripDemo; sourceTree = ""; }; 810379DC1ACD6E0A0013124A /* Supporting Files */ = { isa = PBXGroup; children = ( 810379DD1ACD6E0A0013124A /* Info.plist */, 810379DE1ACD6E0A0013124A /* main.m */, ); name = "Supporting Files"; sourceTree = ""; }; 810379F51ACD6E0A0013124A /* TripDemoTests */ = { isa = PBXGroup; children = ( 810379F81ACD6E0A0013124A /* TripDemoTests.m */, 810379F61ACD6E0A0013124A /* Supporting Files */, ); path = TripDemoTests; sourceTree = ""; }; 810379F61ACD6E0A0013124A /* Supporting Files */ = { isa = PBXGroup; children = ( 810379F71ACD6E0A0013124A /* Info.plist */, ); name = "Supporting Files"; sourceTree = ""; }; C12DD25E80D1C4CC38F306F9 /* Pods */ = { isa = PBXGroup; children = ( E85CDFD9CCB0E2D041F8D094 /* Pods-TripDemo.debug.xcconfig */, 50AB20858F2ADB96B975925F /* Pods-TripDemo.release.xcconfig */, ); name = Pods; sourceTree = ""; }; C81057941AD390DD00CD0D55 /* MovingAnnotation */ = { isa = PBXGroup; children = ( C81057951AD390DD00CD0D55 /* CACoordLayer.h */, C81057961AD390DD00CD0D55 /* CACoordLayer.m */, C81057971AD390DD00CD0D55 /* MovingAnnotationView.h */, C81057981AD390DD00CD0D55 /* MovingAnnotationView.m */, ); path = MovingAnnotation; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ 810379D81ACD6E0A0013124A /* TripDemo */ = { isa = PBXNativeTarget; buildConfigurationList = 810379FC1ACD6E0A0013124A /* Build configuration list for PBXNativeTarget "TripDemo" */; buildPhases = ( 28AB00283D1635E57ECBAE8A /* [CP] Check Pods Manifest.lock */, 810379D51ACD6E0A0013124A /* Sources */, 810379D61ACD6E0A0013124A /* Frameworks */, 810379D71ACD6E0A0013124A /* Resources */, F84D536F332FCDFB19B89B1C /* [CP] Embed Pods Frameworks */, 80EF183DFA680E0147E054C0 /* [CP] Copy Pods Resources */, ); buildRules = ( ); dependencies = ( ); name = TripDemo; productName = TripDemo; productReference = 810379D91ACD6E0A0013124A /* TripDemo.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 810379D11ACD6E090013124A /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0800; ORGANIZATIONNAME = AutoNavi; TargetAttributes = { 810379D81ACD6E0A0013124A = { CreatedOnToolsVersion = 6.2; DevelopmentTeam = YMJ372W38W; ProvisioningStyle = Manual; }; }; }; buildConfigurationList = 810379D41ACD6E090013124A /* Build configuration list for PBXProject "TripDemo" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( en, Base, ); mainGroup = 810379D01ACD6E090013124A; productRefGroup = 810379DA1ACD6E0A0013124A /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( 810379D81ACD6E0A0013124A /* TripDemo */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ 810379D71ACD6E0A0013124A /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( 81037A101ACD7BAE0013124A /* endPoint@2x.png in Resources */, C810578F1ACE959200CD0D55 /* location@2x.png in Resources */, 81B5E9A81AD6269400AA7FFE /* icon_passenger@2x.png in Resources */, 81037A0F1ACD7BAE0013124A /* endPoint.png in Resources */, 810379E81ACD6E0A0013124A /* Main.storyboard in Resources */, 81037A121ACD7BAE0013124A /* startPoint.png in Resources */, 81B5E8D91ACE949700AA7FFE /* icon_next@2x.png in Resources */, 81037A131ACD7BAE0013124A /* startPoint@2x.png in Resources */, 810379EA1ACD6E0A0013124A /* Images.xcassets in Resources */, C810579C1AD3AE7D00CD0D55 /* icon_taxi@2x.png in Resources */, 81B5E9711AD3CCB200AA7FFE /* Launch Screen.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ 28AB00283D1635E57ECBAE8A /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 80EF183DFA680E0147E054C0 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); name = "[CP] Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TripDemo/Pods-TripDemo-resources.sh\"\n"; showEnvVarsInLog = 0; }; F84D536F332FCDFB19B89B1C /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TripDemo/Pods-TripDemo-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ 810379D51ACD6E0A0013124A /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 81B5E8D71ACE8B1800AA7FFE /* DDLocationControl.m in Sources */, 81B5E9A11AD61EF000AA7FFE /* DDTaxiCallRequest.m in Sources */, C81057891ACE791600CD0D55 /* MANaviRoute.m in Sources */, C810578D1ACE7A8100CD0D55 /* CommonUtility.m in Sources */, 81B5E8D01ACE3E3A00AA7FFE /* DDSearchViewController.m in Sources */, 810379E51ACD6E0A0013124A /* ViewController.m in Sources */, 81037A091ACD7ABA0013124A /* DDLocation.m in Sources */, C810579A1AD390DD00CD0D55 /* MovingAnnotationView.m in Sources */, 810379E21ACD6E0A0013124A /* AppDelegate.m in Sources */, 810379DF1ACD6E0A0013124A /* main.m in Sources */, 81B5E9A01AD61EF000AA7FFE /* DDDriver.m in Sources */, C81057991AD390DD00CD0D55 /* CACoordLayer.m in Sources */, 81B5E8D31ACE47DE00AA7FFE /* DDSearchManager.m in Sources */, 81037A051ACD79CB0013124A /* DDLocationView.m in Sources */, C81057921AD38CEF00CD0D55 /* Toast+UIView.m in Sources */, C81057811ACE49BE00CD0D55 /* DDDriverManager.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ 810379E61ACD6E0A0013124A /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( 810379E71ACD6E0A0013124A /* Base */, ); name = Main.storyboard; sourceTree = ""; }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ 810379FA1ACD6E0A0013124A /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.2; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; }; 810379FB1ACD6E0A0013124A /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; name = Release; }; 810379FD1ACD6E0A0013124A /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = E85CDFD9CCB0E2D041F8D094 /* Pods-TripDemo.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; DEVELOPMENT_TEAM = YMJ372W38W; INFOPLIST_FILE = TripDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.autonavi.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = "87cd0391-16b0-4688-90bd-386a7bfa6ffc"; PROVISIONING_PROFILE_SPECIFIER = openPlatform_development; }; name = Debug; }; 810379FE1ACD6E0A0013124A /* Release */ = { isa = XCBuildConfiguration; baseConfigurationReference = 50AB20858F2ADB96B975925F /* Pods-TripDemo.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; DEVELOPMENT_TEAM = YMJ372W38W; INFOPLIST_FILE = TripDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.autonavi.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = "87cd0391-16b0-4688-90bd-386a7bfa6ffc"; PROVISIONING_PROFILE_SPECIFIER = openPlatform_development; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ 810379D41ACD6E090013124A /* Build configuration list for PBXProject "TripDemo" */ = { isa = XCConfigurationList; buildConfigurations = ( 810379FA1ACD6E0A0013124A /* Debug */, 810379FB1ACD6E0A0013124A /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 810379FC1ACD6E0A0013124A /* Build configuration list for PBXNativeTarget "TripDemo" */ = { isa = XCConfigurationList; buildConfigurations = ( 810379FD1ACD6E0A0013124A /* Debug */, 810379FE1ACD6E0A0013124A /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = 810379D11ACD6E090013124A /* Project object */; } ================================================ FILE: TripDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: TripDemo.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: TripDemoTests/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier com.autonavi.$(PRODUCT_NAME:rfc1034identifier) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType BNDL CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1 ================================================ FILE: TripDemoTests/TripDemoTests.m ================================================ // // TripDemoTests.m // TripDemoTests // // Created by xiaoming han on 15/4/2. // Copyright (c) 2015年 AutoNavi. All rights reserved. // #import #import @interface TripDemoTests : XCTestCase @end @implementation TripDemoTests - (void)setUp { [super setUp]; // Put setup code here. This method is called before the invocation of each test method in the class. } - (void)tearDown { // Put teardown code here. This method is called after the invocation of each test method in the class. [super tearDown]; } - (void)testExample { // This is an example of a functional test case. XCTAssert(YES, @"Pass"); } - (void)testPerformanceExample { // This is an example of a performance test case. [self measureBlock:^{ // Put the code you want to measure the time of here. }]; } @end