core_location_fluttify
This commit is contained in:
12
lib/core_location_fluttify.dart
Normal file
12
lib/core_location_fluttify.dart
Normal file
@ -0,0 +1,12 @@
|
||||
library core_location_fluttify;
|
||||
|
||||
export 'package:foundation_fluttify/foundation_fluttify.dart';
|
||||
|
||||
export 'src/cl_authorization_status.dart';
|
||||
export 'src/cl_floor.dart';
|
||||
export 'src/cl_heading.dart';
|
||||
export 'src/cl_location.dart';
|
||||
export 'src/cl_location_coordinate_2d.dart';
|
||||
export 'src/cl_location_manager.dart';
|
||||
export 'src/functions.dart';
|
||||
export 'src/latlng.dart';
|
18
lib/src/cl_authorization_status.dart
Normal file
18
lib/src/cl_authorization_status.dart
Normal file
@ -0,0 +1,18 @@
|
||||
enum CLAuthorizationStatus {
|
||||
kCLAuthorizationStatusNotDetermined,
|
||||
kCLAuthorizationStatusRestricted,
|
||||
kCLAuthorizationStatusDenied,
|
||||
kCLAuthorizationStatusAuthorizedAlways,
|
||||
kCLAuthorizationStatusAuthorizedWhenInUse,
|
||||
kCLAuthorizationStatusAuthorized,
|
||||
}
|
||||
|
||||
extension CLAuthorizationStatusToX on CLAuthorizationStatus {
|
||||
int toValue() => index;
|
||||
}
|
||||
|
||||
extension CLAuthorizationStatusFromX on int {
|
||||
CLAuthorizationStatus toCLAuthorizationStatus() {
|
||||
return CLAuthorizationStatus.values[this];
|
||||
}
|
||||
}
|
14
lib/src/cl_floor.dart
Normal file
14
lib/src/cl_floor.dart
Normal file
@ -0,0 +1,14 @@
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
import 'package:foundation_fluttify/foundation_fluttify.dart';
|
||||
|
||||
import 'objects.dart';
|
||||
|
||||
class CLFloor extends NSObject {
|
||||
@override
|
||||
final String tag__ = 'core_location_fluttify';
|
||||
|
||||
Future<String?> get level {
|
||||
return kCLMethodChannel
|
||||
.invokeMethod('CLFloor::get_level', {'__this__': this});
|
||||
}
|
||||
}
|
24
lib/src/cl_heading.dart
Normal file
24
lib/src/cl_heading.dart
Normal file
@ -0,0 +1,24 @@
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
import 'package:foundation_fluttify/foundation_fluttify.dart';
|
||||
|
||||
import 'objects.dart';
|
||||
|
||||
class CLHeading extends Ref {
|
||||
@override
|
||||
final String tag__ = 'core_location_fluttify';
|
||||
|
||||
Future<double?> get magneticHeading {
|
||||
return kCLMethodChannel
|
||||
.invokeMethod('CLHeading::getMagneticHeading', {'__this__': this});
|
||||
}
|
||||
|
||||
Future<double?> get trueHeading {
|
||||
return kCLMethodChannel
|
||||
.invokeMethod('CLHeading::getTrueHeading', {'__this__': this});
|
||||
}
|
||||
|
||||
Future<double?> get headingAccuracy {
|
||||
return kCLMethodChannel
|
||||
.invokeMethod('CLHeading::getHeadingAccuracy', {'__this__': this});
|
||||
}
|
||||
}
|
48
lib/src/cl_location.dart
Normal file
48
lib/src/cl_location.dart
Normal file
@ -0,0 +1,48 @@
|
||||
import 'package:foundation_fluttify/foundation_fluttify.dart';
|
||||
|
||||
import 'cl_floor.dart';
|
||||
import 'cl_location_coordinate_2d.dart';
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
import 'objects.dart';
|
||||
|
||||
class CLLocation extends NSObject {
|
||||
@override
|
||||
final String tag__ = 'core_location_fluttify';
|
||||
|
||||
Future<CLLocationCoordinate2D> get coordinate async {
|
||||
final result = await kCLMethodChannel
|
||||
.invokeMethod<Ref>('CLLocation::get_coordinate', {'__this__': this});
|
||||
return CLLocationCoordinate2D()..refId = result?.refId;
|
||||
}
|
||||
|
||||
Future<double?> get altitude {
|
||||
return kCLMethodChannel
|
||||
.invokeMethod('CLLocation::get_altitude', {'__this__': this});
|
||||
}
|
||||
|
||||
Future<double?> get horizontalAccuracy {
|
||||
return kCLMethodChannel
|
||||
.invokeMethod('CLLocation::get_horizontalAccuracy', {'__this__': this});
|
||||
}
|
||||
|
||||
Future<double?> get verticalAccuracy {
|
||||
return kCLMethodChannel
|
||||
.invokeMethod('CLLocation::get_verticalAccuracy', {'__this__': this});
|
||||
}
|
||||
|
||||
Future<double?> get course {
|
||||
return kCLMethodChannel
|
||||
.invokeMethod('CLLocation::get_course', {'__this__': this});
|
||||
}
|
||||
|
||||
Future<double?> get speed {
|
||||
return kCLMethodChannel
|
||||
.invokeMethod('CLLocation::get_speed', {'__this__': this});
|
||||
}
|
||||
|
||||
Future<CLFloor?> get floor async {
|
||||
final result = await kCLMethodChannel
|
||||
.invokeMethod<Ref>('CLLocation::get_floor', {'__this__': this});
|
||||
return CLFloor()..refId = result?.refId;
|
||||
}
|
||||
}
|
69
lib/src/cl_location_coordinate_2d.dart
Normal file
69
lib/src/cl_location_coordinate_2d.dart
Normal file
@ -0,0 +1,69 @@
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
import 'package:foundation_fluttify/foundation_fluttify.dart';
|
||||
|
||||
import 'objects.dart';
|
||||
|
||||
class CLLocationCoordinate2D extends Ref {
|
||||
@override
|
||||
final String tag__ = 'core_location_fluttify';
|
||||
|
||||
static Future<CLLocationCoordinate2D> create(
|
||||
double latitude,
|
||||
double longitude,
|
||||
) async {
|
||||
final result = await kCLMethodChannel.invokeMethod<Ref>(
|
||||
'CLLocationCoordinate2D::createCLLocationCoordinate2D',
|
||||
{'latitude': latitude, 'longitude': longitude},
|
||||
);
|
||||
return CLLocationCoordinate2D()..refId = result?.refId;
|
||||
}
|
||||
|
||||
// ignore: non_constant_identifier_names
|
||||
static Future<List<CLLocationCoordinate2D>> create_batch(
|
||||
List<double> latitudeBatch,
|
||||
List<double> longitudeBatch,
|
||||
) async {
|
||||
final resultBatch = await kCLMethodChannel.invokeListMethod<Ref>(
|
||||
'CLLocationCoordinate2D::create_batchCLLocationCoordinate2D',
|
||||
{
|
||||
'latitude_batch': latitudeBatch,
|
||||
'longitude_batch': longitudeBatch,
|
||||
},
|
||||
);
|
||||
return resultBatch!
|
||||
.map((it) => CLLocationCoordinate2D()..refId = it.refId)
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<double?> get latitude {
|
||||
return kCLMethodChannel.invokeMethod(
|
||||
'CLLocationCoordinate2D::get_latitude', {'__this__': this});
|
||||
}
|
||||
|
||||
Future<double?> get longitude {
|
||||
return kCLMethodChannel.invokeMethod(
|
||||
'CLLocationCoordinate2D::get_longitude', {'__this__': this});
|
||||
}
|
||||
}
|
||||
|
||||
extension CLLocationCoordinate2DListX on List<CLLocationCoordinate2D> {
|
||||
Future<List<double>?> get latitudeBatch async {
|
||||
final result = await kCLMethodChannel.invokeListMethod<double>(
|
||||
'CLLocationCoordinate2D::get_latitude_batch',
|
||||
[
|
||||
for (final __item__ in this) {'__this__': __item__}
|
||||
],
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<List<double>?> get longitudeBatch async {
|
||||
final result = await kCLMethodChannel.invokeListMethod<double>(
|
||||
'CLLocationCoordinate2D::get_longitude_batch',
|
||||
[
|
||||
for (final __item__ in this) {'__this__': __item__}
|
||||
],
|
||||
);
|
||||
return result;
|
||||
}
|
||||
}
|
19
lib/src/cl_location_manager.dart
Normal file
19
lib/src/cl_location_manager.dart
Normal file
@ -0,0 +1,19 @@
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
import 'package:foundation_fluttify/foundation_fluttify.dart';
|
||||
|
||||
import 'objects.dart';
|
||||
|
||||
class CLLocationManager extends NSObject {
|
||||
@override
|
||||
final String tag__ = 'core_location_fluttify';
|
||||
|
||||
Future<void> requestAlwaysAuthorization() async {
|
||||
await kCLMethodChannel.invokeMethod(
|
||||
'CLLocationManager::requestAlwaysAuthorization', {'__this__': this});
|
||||
}
|
||||
|
||||
Future<void> requestWhenInUseAuthorization() async {
|
||||
await kCLMethodChannel.invokeMethod(
|
||||
'CLLocationManager::requestWhenInUseAuthorization', {'__this__': this});
|
||||
}
|
||||
}
|
24
lib/src/functions.dart
Normal file
24
lib/src/functions.dart
Normal file
@ -0,0 +1,24 @@
|
||||
import 'package:foundation_fluttify/foundation_fluttify.dart';
|
||||
|
||||
import 'cl_heading.dart';
|
||||
import 'cl_location.dart';
|
||||
import 'cl_location_coordinate_2d.dart';
|
||||
import 'cl_location_manager.dart';
|
||||
|
||||
T? CoreLocationFluttifyAndroidAs<T>(dynamic __this__) {
|
||||
return null;
|
||||
}
|
||||
|
||||
T? CoreLocationFluttifyIOSAs<T>(dynamic __this__) {
|
||||
if (T == CLLocation) {
|
||||
return (CLLocation()..refId = (__this__ as Ref).refId) as T;
|
||||
} else if (T == CLHeading) {
|
||||
return (CLHeading()..refId = (__this__ as Ref).refId) as T;
|
||||
} else if (T == CLLocationCoordinate2D) {
|
||||
return (CLLocationCoordinate2D()..refId = (__this__ as Ref).refId) as T;
|
||||
} else if (T == CLLocationManager) {
|
||||
return (CLLocationManager()..refId = (__this__ as Ref).refId) as T;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
36
lib/src/latlng.dart
Normal file
36
lib/src/latlng.dart
Normal file
@ -0,0 +1,36 @@
|
||||
class LatLng {
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
|
||||
LatLng(this.latitude, this.longitude)
|
||||
: assert(latitude >= -90 && latitude <= 90, '纬度范围为[-90, 90]!'),
|
||||
assert(longitude >= -180 && longitude <= 180, '经度范围为[-180, 180]!');
|
||||
|
||||
static LatLng? fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null || json.isEmpty) return null;
|
||||
return LatLng(json['latitude'], json['longitude']);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is LatLng &&
|
||||
runtimeType == other.runtimeType &&
|
||||
latitude == other.latitude &&
|
||||
longitude == other.longitude;
|
||||
|
||||
@override
|
||||
int get hashCode => latitude.hashCode ^ longitude.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'LatLng{latitude: $latitude, longitude: $longitude}';
|
||||
}
|
||||
}
|
7
lib/src/objects.dart
Normal file
7
lib/src/objects.dart
Normal file
@ -0,0 +1,7 @@
|
||||
import 'package:core_location_fluttify/core_location_fluttify.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
const kCLMethodChannel = MethodChannel(
|
||||
"com.fluttify/core_location_method",
|
||||
StandardMethodCodec(FluttifyMessageCodec()),
|
||||
);
|
Reference in New Issue
Block a user