mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Switch to using real location data (#4282)
This commit is contained in:
parent
8c805e234d
commit
52cf289101
@ -4,7 +4,11 @@
|
|||||||
|
|
||||||
#import "LocationProvider.h"
|
#import "LocationProvider.h"
|
||||||
|
|
||||||
@implementation LocationProvider
|
#import <CoreLocation/CoreLocation.h>
|
||||||
|
|
||||||
|
@implementation LocationProvider {
|
||||||
|
CLLocationManager* _locationManager;
|
||||||
|
}
|
||||||
|
|
||||||
@synthesize messageName = _messageName;
|
@synthesize messageName = _messageName;
|
||||||
|
|
||||||
@ -16,9 +20,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*)didReceiveString:(NSString*)message {
|
- (NSString*)didReceiveString:(NSString*)message {
|
||||||
|
if (_locationManager == nil) {
|
||||||
|
_locationManager = [[CLLocationManager alloc] init];
|
||||||
|
[_locationManager startMonitoringSignificantLocationChanges];
|
||||||
|
}
|
||||||
|
|
||||||
|
CLLocation* location = _locationManager.location;
|
||||||
|
|
||||||
NSDictionary* response = @{
|
NSDictionary* response = @{
|
||||||
@"latitude": @3.29334,
|
@"latitude": @(location.coordinate.latitude),
|
||||||
@"longitude": @8.2492492
|
@"longitude": @(location.coordinate.longitude),
|
||||||
};
|
};
|
||||||
|
|
||||||
NSData* data = [NSJSONSerialization dataWithJSONObject:response options:0 error:nil];
|
NSData* data = [NSJSONSerialization dataWithJSONObject:response options:0 error:nil];
|
||||||
|
@ -57,10 +57,10 @@ class _HelloServicesState extends State<HelloServices> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onReceivedLocation(String json) {
|
void _onReceivedLocation(String json) {
|
||||||
Map<String, double> reply = JSON.decode(json);
|
Map<String, num> reply = JSON.decode(json);
|
||||||
setState(() {
|
setState(() {
|
||||||
_latitude = reply['latitude'];
|
_latitude = reply['latitude'].toDouble();
|
||||||
_longitude = reply['longitude'];
|
_longitude = reply['longitude'].toDouble();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user