-
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathgeocoding_android.dart
More file actions
104 lines (88 loc) · 2.42 KB
/
geocoding_android.dart
File metadata and controls
104 lines (88 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:geocoding_platform_interface/geocoding_platform_interface.dart';
const MethodChannel _channel = MethodChannel('flutter.baseflow.com/geocoding');
/// An implementation of [GeocodingPlatform] for Android.
class GeocodingAndroid extends GeocodingPlatform {
/// Registers this class as the default instance of [GeocodingPlatform].
static void registerWith() {
GeocodingPlatform.instance = GeocodingAndroid();
}
@override
Future<void> setLocaleIdentifier(
String localeIdentifier,
) {
final parameters = <String, String>{
'localeIdentifier': localeIdentifier,
};
return _channel.invokeMethod('setLocaleIdentifier', parameters);
}
@override
Future<List<Location>> locationFromAddress(
String address, {
Region? targetRegion,
}) async {
final parameters = <String, String>{
'address': address,
};
try {
final placemarks = await _channel.invokeMethod(
'locationFromAddress',
parameters,
);
return Location.fromMaps(placemarks);
} on PlatformException catch (e) {
_handlePlatformException(e);
rethrow;
}
}
@override
Future<bool> isPresent() async {
try {
final isPresent = await _channel.invokeMethod(
'isPresent',
);
return isPresent;
} on PlatformException catch (e) {
_handlePlatformException(e);
rethrow;
}
}
@override
Future<List<Placemark>> placemarkFromCoordinates(
double latitude,
double longitude,
) async {
final parameters = <String, dynamic>{
'latitude': latitude,
'longitude': longitude,
};
final placemarks =
await _channel.invokeMethod('placemarkFromCoordinates', parameters);
return Placemark.fromMaps(placemarks);
}
@override
Future<List<Placemark>> placemarkFromAddress(
String address,
) async {
final parameters = <String, String>{
'address': address,
};
try {
final placemarks = await _channel.invokeMethod(
'placemarkFromAddress',
parameters,
);
return Placemark.fromMaps(placemarks);
} on PlatformException catch (e) {
_handlePlatformException(e);
rethrow;
}
}
void _handlePlatformException(PlatformException platformException) {
switch (platformException.code) {
case 'NOT_FOUND':
throw const NoResultFoundException();
}
}
}