Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Location metadata #48

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
}

dependencies {
implementation 'io.radar:sdk:3.9.8'
implementation 'io.radar:sdk:3.11.0'
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.google.code.gson:gson:2.8.6'
}
16 changes: 8 additions & 8 deletions android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private void initialize(MethodCall call, Result result) {
String publishableKey = call.argument("publishableKey");
SharedPreferences.Editor editor = mContext.getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit();
editor.putString("x_platform_sdk_type", "Flutter");
editor.putString("x_platform_sdk_version", "3.9.1");
editor.putString("x_platform_sdk_version", "3.9.2-beta.5");
editor.apply();
Radar.initialize(mContext, publishableKey);
result.success(true);
Expand Down Expand Up @@ -847,13 +847,10 @@ public void run() {
String[] tags = (String[])tagsList.toArray(new String[0]);
HashMap metadataMap = (HashMap)call.argument("metadata");
JSONObject metadata = jsonForMap(metadataMap);
int limit = call.hasArgument("limit") ? (int)call.argument("limit") : 10;
int limit = call.hasArgument("limit") ? (int)call.argument("limit") : -1;

if (near != null) {
Radar.searchGeofences(near, radius, tags, metadata, limit, callback);
} else {
Radar.searchGeofences(radius, tags, metadata, limit, callback);
}
boolean includeGeometry = call.hasArgument("includeGeometry") ? (boolean)call.argument("includeGeometry") : false;
Radar.searchGeofences(near, radius, tags, metadata, limit, includeGeometry, callback);
}

public void searchPlaces(MethodCall call, final Result result) {
Expand Down Expand Up @@ -908,7 +905,10 @@ public void run() {
public void autocomplete(MethodCall call, final Result result) {
String query = call.argument("query");
HashMap nearMap = (HashMap)call.argument("near");
Location near = locationForMap(nearMap);
Location near = null;
if (nearMap != null) {
near = locationForMap(nearMap);
}
int limit = call.hasArgument("limit") ? (int)call.argument("limit") : 10;
String country = call.argument("country");
ArrayList layersList = (ArrayList)call.argument("layers");
Expand Down
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "io.radar.example"
minSdkVersion 16
minSdkVersion flutter.minSdkVersion
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand All @@ -49,7 +49,7 @@ android {
}

dependencies {
implementation 'io.radar:sdk:3.9.8'
implementation 'io.radar:sdk:3.11.0'
implementation "com.google.android.play:integrity:1.2.0"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '11.0'
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
25 changes: 23 additions & 2 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -149,6 +149,7 @@
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
6DC24095C2EFCA483D13C630 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -165,7 +166,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -208,10 +209,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -220,6 +223,23 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin\n";
};
6DC24095C2EFCA483D13C630 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
8AED107CD2EAE06C6755A899 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -244,6 +264,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
8 changes: 8 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>YOUR TEXT</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>YOUR TEXT</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Your iOS 11 and higher background location usage description goes here. e.g., "This app uses your location in the background to recommend places nearby."</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Your iOS 10 and lower background location usage description goes here. e.g., "This app uses your location in the background to recommend places nearby."</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your foreground location usage description goes here. e.g., "This app uses your location in the foreground to recommend places nearby."</string>
<key>NSMotionUsageDescription</key>
<string>We use motion data to improve the accuracy of locations</string>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
Expand Down Expand Up @@ -78,5 +84,7 @@
</dict>
</dict>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
19 changes: 18 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
@pragma('vm:entry-point')
static void onLocation(Map res) {
print('📍📍 onLocation: $res');
print("METADATA: $res['locationMetadata']");
}

@pragma('vm:entry-point')
Expand Down Expand Up @@ -255,7 +256,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
style: raisedButtonStyle,
onPressed: () async {
var resp = await Radar.autocomplete(
query: 'brooklyn roasting',
query: '841 Broadwa',
near: {
'latitude': 40.783826,
'longitude': -73.975363,
Expand All @@ -269,6 +270,22 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
},
child: Text('autocomplete'),
),
ElevatedButton(
style: raisedButtonStyle,
onPressed: () async {
var resp = await Radar.autocomplete(
query: '841 Broadwa',
near: {},
limit: 10,
layers: ['address', 'street'],
country: 'US',
mailable: false
);
print("autocomplete: $resp");
},
child: Text('autocomplete without near'),
),

ElevatedButton(
style: raisedButtonStyle,
onPressed: () async {
Expand Down
34 changes: 25 additions & 9 deletions ios/Classes/RadarFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ - (void)initialize:(FlutterMethodCall *)call withResult:(FlutterResult)result {

NSString *publishableKey = argsDict[@"publishableKey"];
[[NSUserDefaults standardUserDefaults] setObject:@"Flutter" forKey:@"radar-xPlatformSDKType"];
[[NSUserDefaults standardUserDefaults] setObject:@"3.9.1" forKey:@"radar-xPlatformSDKVersion"];
[[NSUserDefaults standardUserDefaults] setObject:@"3.9.2-beta.5" forKey:@"radar-xPlatformSDKVersion"];
[Radar initializeWithPublishableKey:publishableKey];
result(nil);
}
Expand Down Expand Up @@ -637,14 +637,17 @@ - (void)searchGeofences:(FlutterMethodCall *)call withResult:(FlutterResult)resu
if (limitNumber != nil && [limitNumber isKindOfClass:[NSNumber class]]) {
limit = [limitNumber intValue];
} else {
limit = 10;
limit = -1;
}

if (near != nil) {
[Radar searchGeofencesNear:near radius:radius tags:tags metadata:metadata limit:limit completionHandler:completionHandler];
} else {
[Radar searchGeofencesWithRadius:radius tags:tags metadata:metadata limit:limit completionHandler:completionHandler];
// boolean for includeGeometry
BOOL includeGeometry = NO;
NSNumber *includeGeometryNumber = argsDict[@"includeGeometry"];
if (includeGeometryNumber != nil && [includeGeometryNumber isKindOfClass:[NSNumber class]]) {
includeGeometry = [includeGeometryNumber boolValue];
}

[Radar searchGeofencesNear:near radius:radius tags:tags metadata:metadata limit:limit includeGeometry:includeGeometry completionHandler:completionHandler];
}

- (void)searchPlaces:(FlutterMethodCall *)call withResult:(FlutterResult)result {
Expand Down Expand Up @@ -705,12 +708,14 @@ - (void)autocomplete:(FlutterMethodCall *)call withResult:(FlutterResult)result
NSString *query = argsDict[@"query"];
CLLocation *near;
NSDictionary *nearDict = argsDict[@"near"];
if (nearDict) {
if (nearDict != nil && [nearDict isKindOfClass:[NSDictionary class]]) {
NSNumber *latitudeNumber = nearDict[@"latitude"];
NSNumber *longitudeNumber = nearDict[@"longitude"];
double latitude = [latitudeNumber doubleValue];
double longitude = [longitudeNumber doubleValue];
near = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(latitude, longitude) altitude:-1 horizontalAccuracy:5 verticalAccuracy:-1 timestamp:[NSDate date]];
} else {
near = nil;
}
NSNumber *limitNumber = argsDict[@"limit"];
int limit;
Expand Down Expand Up @@ -1067,8 +1072,19 @@ - (void)didReceiveEvents:(NSArray<RadarEvent *> *)events user:(RadarUser *)user
[self.backgroundChannel invokeMethod:@"" arguments:args];
}

- (void)didUpdateLocation:(CLLocation *)location user:(RadarUser *)user {
NSDictionary *dict = @{@"location": [Radar dictionaryForLocation:location], @"user": [user dictionaryValue]};
- (void)didUpdateLocation:(CLLocation *)location user:(RadarUser *)user locationMetadata:(NSDictionary *)locationMetadata{

NSMutableDictionary *dict = [NSMutableDictionary new];
if ([Radar dictionaryForLocation:location]) {
[dict setObject:[Radar dictionaryForLocation:location] forKey:@"location"];
}
if ([user dictionaryValue]) {
[dict setObject:[user dictionaryValue] forKey:@"user"];
}
if (locationMetadata) {
[dict setObject:locationMetadata forKey:@"locationMetadata"];
}

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSInteger callbackHandle = [userDefaults integerForKey:@"location"];
if (callbackHandle == 0) {
Expand Down
4 changes: 2 additions & 2 deletions ios/flutter_radar.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'flutter_radar'
s.version = '3.9.1'
s.version = '3.9.2-beta.5'
s.summary = 'Flutter package for Radar, the leading geofencing and location tracking platform'
s.description = 'Flutter package for Radar, the leading geofencing and location tracking platform'
s.homepage = 'http://example.com'
Expand All @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'RadarSDK', '3.9.14'
s.dependency 'RadarSDK', '3.10.2-beta.1'
s.platform = :ios, '10.0'
s.static_framework = true

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_radar
description: Flutter package for Radar, the leading geofencing and location tracking platform
version: 3.9.1
version: 3.9.2-beta.5
homepage: https://github.com/radarlabs/flutter-radar

environment:
Expand Down
Loading