Files
tianrunCRM/Assets/3rd/LBSBaidu/Plugins/iOS/SingleLocPlugin.m

155 lines
5.3 KiB
Mathematica
Raw Normal View History

2020-07-04 14:41:25 +08:00
//
// SingleLocDemoViewController.m
// IphoneMapSdkDemo
//
// Created by baidu on 2017/4/5.
// Copyright © 2017 Baidu. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "SingleLocPlugin.h"
static SingleLocPlugin* _singleLocPlugin;
@implementation SingleLocPlugin
+(SingleLocPlugin*) instance
{
if (_singleLocPlugin != nil) {
return _singleLocPlugin;
} else {
_singleLocPlugin =(SingleLocPlugin*)([[SingleLocPlugin alloc] init]);
}
return _singleLocPlugin;
}
- (id)init:(NSString *)ak withUnityListner:(NSString *)listner andCoorType:(int)coordinateType
{
unityListner = listner;
[[BMKLocationAuth sharedInstance] checkPermisionWithKey:ak authDelegate:self];
[self initLocation:coordinateType];
return self;
}
-(void)initLocation:(int)coordinateType
{
_locationManager = [[BMKLocationManager alloc] init];
_locationManager.delegate = self;
if(coordinateType == 0) {
_locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;
} else if(coordinateType == 1) {
_locationManager.coordinateType = BMKLocationCoordinateTypeBMK09MC;
} else if(coordinateType == 2) {
_locationManager.coordinateType = BMKLocationCoordinateTypeWGS84;
} else {
_locationManager.coordinateType = BMKLocationCoordinateTypeGCJ02;
}
_locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL; //BMKLocationCoordinateTypeGCJ02
_locationManager.distanceFilter = [distance.text doubleValue];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.activityType = CLActivityTypeAutomotiveNavigation;
_locationManager.pausesLocationUpdatesAutomatically = NO;
_locationManager.allowsBackgroundLocationUpdates = NO;// YES
_locationManager.locationTimeout = 10;
_locationManager.reGeocodeTimeout = 10;
}
-(void)getMyLocation
{
self.completionBlock = ^(BMKLocation *location, BMKLocationNetworkState state, NSError *error)
{
long code = 0
NSString *msg = nil;
float latitude = 0;
float longitude = 0;
NSString *AddrStr = @"";
if (error)
{
code = (long)error.code;
msg = error.localizedDescription;
NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
}
if (location.location) {//annotation
NSLog(@"LOC = %@",location.location);
NSLog(@"LOC ID= %@",location.locationID);
latitude = location.location.coordinate.latitude;
longitude = location.location.coordinate.longitude;
if(location.rgcData) {
AddrStr = [location.rgcData description];
}
NSLog([NSString stringWithFormat:@"当前位置信息: \n经纬度%.6f,%.6f \n地址信息%@ \n网络状态%d",location.location.coordinate.latitude, location.location.coordinate.longitude, AddrStr, state]);
}
NSLog(@"netstate = %d",state);
NSString * json = [NSString stringWithFormat:@"{\"cmd\":\"onGetLocation\", \"code\":%ld,\"msg\":\"%@\",\"latitude\":%0.6f,\"longitude\":%0.6f,\"AddrStr\":\"%@\"}",code, msg, latitude, longitude, AddrStr];
[self sendUnityMessage:@"onCallback", json]
};
}
-(void) sendUnityMessage:(const NSString*)method with:(NSString*)msg
{
if(unityListner != nil && msg != nil) {
UnitySendMessage([unityListner UTF8String],
[method UTF8String], [msg UTF8String]);
}
}
- (void)onGetPermissionState:(int)iError
{
if (0 == iError) {
NSLog(@"授权成功");
}
else {
NSLog(@"onGetPermissionState %d",iError);
}
}
- (void)onCheckPermissionState:(BMKLocationAuthErrorCode)iError
{
NSLog(@"location auth onGetPermissionState %ld",(long)iError);
}
/**
* @brief app storeapp store使plistNSLocationAlwaysUsageDescriptionNSLocationAlwaysAndWhenInUseUsageDescriptiondelegateapi[locationManager requestAlwaysAuthorization]NSLocationWhenInUseUsageDescription使delegate
* @param manager BMKLocationManager
* @param locationManager CLLocationManager
* @since 1.6.0
*/
- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager doRequestAlwaysAuthorization:(CLLocationManager * _Nonnull)locationManager
{
[locationManager requestAlwaysAuthorization];
}
- (void)dealloc {
_locationManager = nil;
_completionBlock = nil;
}
@end
#if __cplusplus
extern "C" {
#endif
void _init(const char* ak, const char* goName, const int coorType);
void _getMyLocation();
#if __cplusplus
}
#endif
void _init(const char* ak, const char* goName, const int coorType); {
[[SingleLocPlugin instance] init:[[NSString stringWithUTF8String:ak] withUnityListner:[NSString stringWithUTF8String:goName andCoorType:coorType] retain]];
}
void _getMyLocation() {
[[SingleLocPlugin instance] getMyLocation];
}