
* Add platform_services sample * update build.gradle to use latest scripts * use FlutterActivity * Updated ExampleInstrumentedTest.java and deleted FlutterPlugin.groovy * Remove getRandom code from main.dart * remove unused import
40 lines
1.1 KiB
Objective-C
40 lines
1.1 KiB
Objective-C
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#import "LocationProvider.h"
|
|
|
|
#import <CoreLocation/CoreLocation.h>
|
|
|
|
@implementation LocationProvider {
|
|
CLLocationManager* _locationManager;
|
|
}
|
|
|
|
@synthesize messageName = _messageName;
|
|
|
|
- (instancetype) init {
|
|
self = [super init];
|
|
if (self)
|
|
self->_messageName = @"getLocation";
|
|
return self;
|
|
}
|
|
|
|
- (NSString*)didReceiveString:(NSString*)message {
|
|
if (_locationManager == nil) {
|
|
_locationManager = [[CLLocationManager alloc] init];
|
|
[_locationManager startMonitoringSignificantLocationChanges];
|
|
}
|
|
|
|
CLLocation* location = _locationManager.location;
|
|
|
|
NSDictionary* response = @{
|
|
@"latitude": @(location.coordinate.latitude),
|
|
@"longitude": @(location.coordinate.longitude),
|
|
};
|
|
|
|
NSData* data = [NSJSONSerialization dataWithJSONObject:response options:0 error:nil];
|
|
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
}
|
|
|
|
@end
|