-
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathgeocoding_ios.dart
More file actions
77 lines (64 loc) · 1.91 KB
/
geocoding_ios.dart
File metadata and controls
77 lines (64 loc) · 1.91 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
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 iOS.
class GeocodingIOS extends GeocodingPlatform {
/// Registers this class as the default instance of [GeocodingPlatform].
static void registerWith() {
GeocodingPlatform.instance = GeocodingIOS();
}
String? _localeIdentifier;
@override
Future<void> setLocaleIdentifier(
String localeIdentifier,
) async {
_localeIdentifier = localeIdentifier;
}
@override
Future<List<Location>> locationFromAddress(
String address, {
Region? targetRegion,
}) async {
final parameters = <String, String>{
'address': address,
};
if (_localeIdentifier != null) {
parameters['localeIdentifier'] = _localeIdentifier!;
}
try {
final placemarks = await _channel.invokeMethod(
'locationFromAddress',
parameters,
);
return Location.fromMaps(placemarks);
} 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,
};
if (_localeIdentifier != null) {
parameters['localeIdentifier'] = _localeIdentifier!;
}
final placemarks =
await _channel.invokeMethod('placemarkFromCoordinates', parameters);
return Placemark.fromMaps(placemarks);
}
@override
Future<bool> isPresent() => Future<bool>.value(true);
void _handlePlatformException(PlatformException platformException) {
switch (platformException.code) {
case 'NOT_FOUND':
throw const NoResultFoundException();
}
}
}