diff --git a/examples/hello_services/ios/HelloServices/LocationProvider.m b/examples/hello_services/ios/HelloServices/LocationProvider.m index e0d823dc69..e6e0cc7b62 100644 --- a/examples/hello_services/ios/HelloServices/LocationProvider.m +++ b/examples/hello_services/ios/HelloServices/LocationProvider.m @@ -4,7 +4,11 @@ #import "LocationProvider.h" -@implementation LocationProvider +#import + +@implementation LocationProvider { + CLLocationManager* _locationManager; +} @synthesize messageName = _messageName; @@ -16,9 +20,16 @@ } - (NSString*)didReceiveString:(NSString*)message { + if (_locationManager == nil) { + _locationManager = [[CLLocationManager alloc] init]; + [_locationManager startMonitoringSignificantLocationChanges]; + } + + CLLocation* location = _locationManager.location; + NSDictionary* response = @{ - @"latitude": @3.29334, - @"longitude": @8.2492492 + @"latitude": @(location.coordinate.latitude), + @"longitude": @(location.coordinate.longitude), }; NSData* data = [NSJSONSerialization dataWithJSONObject:response options:0 error:nil]; diff --git a/examples/hello_services/lib/main.dart b/examples/hello_services/lib/main.dart index 7e770ce10f..f40cb99de5 100644 --- a/examples/hello_services/lib/main.dart +++ b/examples/hello_services/lib/main.dart @@ -57,10 +57,10 @@ class _HelloServicesState extends State { } void _onReceivedLocation(String json) { - Map reply = JSON.decode(json); + Map reply = JSON.decode(json); setState(() { - _latitude = reply['latitude']; - _longitude = reply['longitude']; + _latitude = reply['latitude'].toDouble(); + _longitude = reply['longitude'].toDouble(); }); } }