Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/debug #111

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ xcuserdata/
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
# Podfile.lock
Pods/
Podfile.lock

# Carthage
#
Expand Down
2 changes: 2 additions & 0 deletions LLDebugTool.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ Pod::Spec.new do |s|
ss.frameworks = "CoreLocation", "MapKit"
ss.pod_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => 'LLDEBUGTOOL_LOCATION=1'}
ss.dependency "LLDebugTool/Core"
ss.dependency "MapxusBaseSDK", "~> 6.8.0"
ss.dependency "MapxusMapSDK", "~> 6.8.0"
end

s.subspec 'ShortCut' do |ss|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ NS_ASSUME_NONNULL_BEGIN
/// Whether is mock
@property (nonatomic, assign, getter=LL_isMock) BOOL LL_mock;


/// This property holds the floor information.
///
/// @discussion
/// Because `CLLocation.floor` does not have a defined setter method, you can change the value when you get `CLLocation.floor` using this property.
/// If it is set to nil, `CLLocation.floor` will return the original value when the getter method is called.
@property (nonatomic, strong, nullable) CLFloor *myLLFloor;

+ (CLLocation *)createLocationWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude level:(NSInteger)level;

@end

NS_ASSUME_NONNULL_END


NS_ASSUME_NONNULL_BEGIN

@interface CLFloor (Factory)

+ (CLFloor *)createFloorWihtLevel:(NSInteger)level;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,50 @@

@implementation CLLocation (LL_Location)

+ (void)load
{
static dispatch_once_t mxmOnceToken;
dispatch_once(&mxmOnceToken, ^{
SEL oldSelector = @selector(floor);
SEL newSelector = @selector(hook_getLLFloor);
Method oldMethod = class_getInstanceMethod([self class], oldSelector);
Method newMethod = class_getInstanceMethod([self class], newSelector);

// 若未实现代理方法,则先添加代理方法
BOOL isSuccess = class_addMethod([self class], oldSelector, class_getMethodImplementation([self class], newSelector), method_getTypeEncoding(newMethod));
if (isSuccess) {
class_replaceMethod([self class], newSelector, class_getMethodImplementation([self class], oldSelector), method_getTypeEncoding(oldMethod));
} else {
method_exchangeImplementations(oldMethod, newMethod);
}
});
}

+ (CLLocation *)createLocationWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude level:(NSInteger)level {
CLLocation *mockLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
CLFloor *floor = [CLFloor createFloorWihtLevel:level];
mockLocation.myLLFloor = floor;
mockLocation.LL_mock = YES;
return mockLocation;
}

- (CLFloor *)hook_getLLFloor
{
if (self.myLLFloor) {
return self.myLLFloor;
} else {
return [self hook_getLLFloor];
}
}

- (CLFloor *)myLLFloor {
return objc_getAssociatedObject(self, @selector(myLLFloor));
}

- (void)setMyLLFloor:(CLFloor *)myLLFloor {
objc_setAssociatedObject(self, @selector(myLLFloor), myLLFloor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)setLL_mock:(BOOL)LL_mock {
objc_setAssociatedObject(self, @selector(LL_isMock), @(LL_mock), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
Expand All @@ -36,3 +80,14 @@ - (BOOL)LL_isMock {
}

@end

@implementation CLFloor (Factory)

+ (CLFloor *)createFloorWihtLevel:(NSInteger)level
{
CLFloor *floor = [[CLFloor alloc] init];
[floor setValue:@(level) forKey:@"level"];
return floor;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// SOFTWARE.

#import <CoreLocation/CoreLocation.h>
#import <MapxusMapSDK/MapxusMapSDK.h>

@class LLLocationProxy;

Expand All @@ -41,3 +42,14 @@ FOUNDATION_EXPORT NSNotificationName const LLCLLocationUnRegisterNotificationNam
@end

NS_ASSUME_NONNULL_END


NS_ASSUME_NONNULL_BEGIN

@interface MGLPointAnnotation (LL_PointAnnotation)

+ (MGLPointAnnotation *)pointAnnotation:(CLLocationCoordinate2D)coordinate;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
// SOFTWARE.

#import "CLLocationManager+LL_Location.h"

#import "LLLocationProxy.h"

#import "NSObject+LL_Runtime.h"

NSNotificationName const LLCLLocationRegisterNotificationName = @"LLCLLocationRegisterNotificationName";
Expand Down Expand Up @@ -103,3 +101,13 @@ - (BOOL)LL_isUpdatingLocation {
}

@end

@implementation MGLPointAnnotation (LL_PointAnnotation)

+ (MGLPointAnnotation *)pointAnnotation:(CLLocationCoordinate2D)coordinate {
MGLPointAnnotation *point = [[MGLPointAnnotation alloc] init];
point.coordinate = coordinate;
point.title = [NSString stringWithFormat:@"%0.6f, %0.6f", coordinate.latitude, coordinate.longitude];
return point;
}
@end
22 changes: 22 additions & 0 deletions LLDebugTool/Core/Component/Location/Function/LLLocationHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

#import <CoreLocation/CoreLocation.h>

double toRadians(double degrees);
double toDegrees(double radians);

@class LLLocationMockRouteModel;

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -93,6 +96,25 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (BOOL)addLLDebugToolExtendDataWithPath:(NSString *)path;


/// <#Description#>
/// - Parameters:
/// - point: <#point description#>
/// - distance: <#distance description#>
/// - angle: <#angle description#>
+ (CLLocation *)pointFromPoint:(CLLocationCoordinate2D)point distance:(double)distance angle:(double)angle;

@end

NS_ASSUME_NONNULL_END

NS_ASSUME_NONNULL_BEGIN

@interface NSNumber (Radians)

+ (CGFloat)toRadians:(CGFloat)degrees;

@end


NS_ASSUME_NONNULL_END
41 changes: 40 additions & 1 deletion LLDebugTool/Core/Component/Location/Function/LLLocationHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#import "CLLocationManager+LL_Location.h"
#import "CLLocation+LL_Location.h"

double toRadians(double degrees) {
return degrees * M_PI / 180.0;
}

double toDegrees(double radians) {
return radians * 180.0 / M_PI;
}

static LLLocationHelper *_instance = nil;

static pthread_mutex_t mutex_t = PTHREAD_MUTEX_INITIALIZER;
Expand Down Expand Up @@ -141,7 +149,6 @@ - (NSString *)stopRecordRoute {
}
NSMutableDictionary *json = [[NSMutableDictionary alloc] init];
json[@"key"] = @"LLDebugTool";
// NSMutableArray *data = [[NSMutableArray alloc] init];
for (CLLocation *location in self.locations) {
NSMutableDictionary *locationJson = [[NSMutableDictionary alloc] init];
locationJson[@"lng"] = [LLFormatterTool formatLocation:@(location.coordinate.longitude)];
Expand Down Expand Up @@ -193,6 +200,29 @@ + (BOOL)addLLDebugToolExtendDataWithPath:(NSString *)path {
return YES;
}

/// <#Description#>
/// - Parameters:
/// - point: <#point description#>
/// - distance: <#distance description#>
/// - angle: <#angle description#>
+ (CLLocation *)pointFromPoint:(CLLocationCoordinate2D)point distance:(double)distance angle:(double)angle {
double lati1 = point.latitude;
double long1 = point.longitude;

double R = 6378137.0; // 球半径
double sinLat = sin(toRadians(lati1));
double cosLat = cos(toRadians(lati1));
double cosDistR = cos(distance / R);
double sinDistR = sin(distance / R);
double lat2 = asin(sinLat * cosDistR + cosLat * sinDistR * cos(toRadians(angle)));
double lon2 = toRadians(long1) + atan2(sin(toRadians(angle)) * sinDistR * cosLat, cosDistR - sinLat * sin(lat2));

lon2 = toDegrees(lon2);
lon2 = lon2 > 180 ? lon2 - 360 : lon2 < -180 ? lon2 + 360 : lon2;
lat2 = toDegrees(lat2);
return [[CLLocation alloc] initWithLatitude:lat2 longitude:lon2];
}

#pragma mark - Life cycle
- (instancetype)init {
if (self = [super init]) {
Expand Down Expand Up @@ -336,3 +366,12 @@ - (CLLocationManager *)locationManager {
}

@end


@implementation NSNumber (Radians)

+ (CGFloat)toRadians:(CGFloat)degrees {
return degrees * M_PI / 180.0;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,17 @@ - (void)analysisJsonFile:(NSString *)filePath {
if (dic[@"lat"] && dic[@"lng"]) {
CLLocationDegrees lat = [dic[@"lat"] doubleValue];
CLLocationDegrees lng = [dic[@"lng"] doubleValue];
NSInteger level = [dic[@"lng"] intValue];
CLFloor *floor = [CLFloor createFloorWihtLevel:level];

CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lng];
location.myLLFloor = floor;
location.LL_mock = YES;
[locations addObject:location];
}
}
}

NSLog(@"*** jsonData = %@", jsonData);
_locations = [locations copy];
_isAvailable = YES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ - (BOOL)respondsToSelector:(SEL)aSelector {

#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
if ([self.target respondsToSelector:_cmd]) {
BOOL responds = [self.target respondsToSelector:_cmd];
// NSLog(@"*** target = %@",self.target);
if (responds) {
if ([LLLocationHelper shared].isMockRoute) {
CLLocation *location = [locations firstObject];
// Mocking route.
Expand All @@ -49,12 +51,12 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray
}
} else if ([LLLocationHelper shared].enable) {
// Mock location.
CLLocation *mockLocation = [[CLLocation alloc] initWithLatitude:[LLConfig shared].mockLocationLatitude longitude:[LLConfig shared].mockLocationLongitude];
mockLocation.LL_mock = YES;
CLLocation *mockLocation = [CLLocation createLocationWithLatitude:[LLConfig shared].mockLocationLatitude longitude:[LLConfig shared].mockLocationLongitude level:[LLConfig shared].mockLocationLevel];
locations = @[mockLocation];
}

[self.target locationManager:manager didUpdateLocations:locations];
[manager requestWhenInUseAuthorization];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
// SOFTWARE.

#import <MapKit/MapKit.h>
#import <MapxusMapSDK/MapxusMapSDK.h>

NS_ASSUME_NONNULL_BEGIN

@interface MKMapView (LL_Location)
@interface MGLMapView (MGL_Location)

@end

Expand Down
Loading