Skip to content

Commit

Permalink
Support for IA SDK 2.3 APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni Nopanen authored Feb 28, 2017
2 parents 260854c + 22568b9 commit 134e447
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 90 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# IndoorAtlas Cordova Plugin
# IndoorAtlas Cordova Plugin 1.1 with IndoorAtlas SDK 2.3

This Cordova plugin provides information about the device's location inside finger printed buildings and uses the [IndoorAtlas location APIs](http://docs.indooratlas.com/cordova/api-documentation).

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-indooratlas",
"version": "1.0",
"version": "1.1.0",
"description": "Cordova plugin using IndoorAtlas positioning API.",
"cordova": {
"id": "cordova-plugin-indooratlas",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-indooratlas"
version="1.0.0">
version="1.1.0">

<name>IndoorAtlas</name>
<description>A Cordova plugin that integrates IndoorAtlas</description>
Expand Down
45 changes: 42 additions & 3 deletions src/android/IALocationPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class IALocationPlugin extends CordovaPlugin{
private Timer mTimer;
private String mApiKey, mApiSecret;
private IALocationRequest mLocationRequest = IALocationRequest.create();

/**
* Called by the WebView implementation to check for geolocation permissions, can be used
* by other Java methods in the event that a plugin is using this as a dependency.
Expand Down Expand Up @@ -195,8 +195,11 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if ("setDistanceFilter".equals(action)) {
float distance = (float) args.getDouble(0);
setDistanceFilter(distance, callbackContext);
} else if ("getTraceId".equals(action)) {
getTraceId(callbackContext);
} else if ("getFloorCertainty".equals(action)) {
getFloorCertainty(callbackContext);
}

}
catch(Exception ex){
Log.e(TAG,ex.toString());
Expand Down Expand Up @@ -332,7 +335,7 @@ public void onResult(IAResult<IAFloorPlan> iaResult) {
callbackContext.error(PositionError.getErrorObject(PositionError.INITIALIZATION_ERROR));
}
}

/**
* Calculates point based on given coordinates
* @param coords
Expand Down Expand Up @@ -562,6 +565,42 @@ private void setDistanceFilter(float distance, CallbackContext callbackContext)
}
}

private void getTraceId(CallbackContext callbackContext) {
JSONObject data;
data = new JSONObject();
try {
data.put("traceId", mLocationManager.getExtraInfo().traceId);
} catch (JSONException ex) {
Log.e(TAG, ex.toString());
throw new IllegalStateException(ex.getMessage());
}
callbackContext.success(data);
}

private void getFloorCertainty(CallbackContext callbackContext) {

if (mListener != null) {
if(mListener.lastKnownLocation != null){
if (mListener.lastKnownLocation.hasFloorCertainty()) {
JSONObject data;
data = new JSONObject();
try {
data.put("floorCertainty", mListener.lastKnownLocation.getFloorCertainty());

} catch (JSONException ex) {
Log.e(TAG, ex.toString());
throw new IllegalStateException(ex.getMessage());
}
callbackContext.success(data);
}
} else {
callbackContext.error("No floor certainty");
}
} else {
callbackContext.error("No floor certainty");
}
}

/**
* Starts IndoorAtlas positioning session
*/
Expand Down
2 changes: 1 addition & 1 deletion src/android/IndoorLocationListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class IndoorLocationListener implements IALocationListener, IARegion.List
private HashMap<String, CallbackContext> regionWatches = new HashMap<String, CallbackContext>();
private ArrayList<CallbackContext> mCallbacks = new ArrayList<CallbackContext>();
private CallbackContext mCallbackContext;
private IALocation lastKnownLocation=null;
public IALocation lastKnownLocation=null;
private IALocationPlugin owner;

/**
Expand Down
7 changes: 4 additions & 3 deletions src/ios/IndoorAtlasLocationService.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef NSUInteger IndoorLocationTransitionType;

@end
@interface IndoorAtlasLocationService : NSObject{

}

@property (nonatomic, weak) id <IALocationDelegate> delegate;
Expand Down Expand Up @@ -123,7 +123,8 @@ typedef NSUInteger IndoorLocationTransitionType;
*/
- (void)getPointToCoordinate:(NSString*)floorplanId andPoint: (CGPoint) point;

- (void)valueForDistanceFilter:(double*)distance;
- (void)valueForDistanceFilter:(float*)distance;
- (float)fetchFloorCertainty;
- (NSString *)fetchTraceId;

@end

43 changes: 26 additions & 17 deletions src/ios/IndoorAtlasLocationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ -(id)init:(NSString *)apikey hash:(NSString *)apisecret
self.apiSecret = apisecret;
// Create IALocationManager and point delegate to receiver
self.manager = [IALocationManager new];

// Set IndoorAtlas API key and secret
[self.manager setApiKey:self.apikey andSecret:self.apiSecret];

self.manager.delegate = self;
serviceStoped = YES;

// Create floor plan manager
self.resourceManager = [IAResourceManager resourceManagerWithLocationManager:self.manager];
}
Expand Down Expand Up @@ -121,7 +121,7 @@ - (void)indoorLocationManager:(IALocationManager *)manager didUpdateLocations:(N
NSLog(@"Invalid Floor");
return;
}

if(self.delegate != nil) {
[self.delegate location:self didUpdateLocation:loc];
}
Expand Down Expand Up @@ -167,18 +167,18 @@ - (void)getCoordinateToPoint:(NSString*)floorplanId andCoordinates: (CLLocationC
NSLog(@"getCoordinateToPoint: previousFloorplanName %@", _previousFloorplan.name);
NSLog(@"getCoordinateToPoint: longitude %f", coords.longitude);
NSLog(@"getCoordinateToPoint: latitude %f", coords.latitude);

__weak IndoorAtlasLocationService *weakSelf = self;

// New floorplan information is not fetched if current and previous ids are the same
// Finally, sendCoordinateToPoint function is called which prepares the data for Cordova and Javascript
if ([floorplanId isEqualToString:self.previousFloorplan.floorPlanId]) {

CGPoint points = [self.previousFloorplan coordinateToPoint:coords];
[weakSelf.delegate sendCoordinateToPoint:points];

} else {

// Fetches new floorplan information and calls sendCoordinateToPoint to send the data to Cordova and Javcascript.
[self.resourceManager fetchFloorPlanWithId:floorplanId andCompletion:^(IAFloorPlan *floorplan, NSError *error) {
if (error) {
Expand All @@ -191,7 +191,7 @@ - (void)getCoordinateToPoint:(NSString*)floorplanId andCoordinates: (CLLocationC
}*/
return;
}

NSLog(@"getCoordinateToPoint: fetched floorplan with id: %@", floorplan.floorPlanId);
CGPoint points = [floorplan coordinateToPoint:coords];
NSLog(@"getCoordinateToPoint: point %@", NSStringFromCGPoint(points));
Expand All @@ -206,17 +206,17 @@ - (void)getPointToCoordinate:(NSString*)floorplanId andPoint: (CGPoint) point
{
NSLog(@"getPointToCoordinate: previousFloorplanName %@", _previousFloorplan.name);
NSLog(@"getPointToCoordinate: point %@", NSStringFromCGPoint(point));

__weak IndoorAtlasLocationService *weakSelf = self;

// New floorplan information is not fetched if current and previous ids are the same
// Finally, sendCoordinateToPoint function is called which prepares the data for Cordova and Javascript
if (floorplanId == self.previousFloorplan.floorPlanId) {

CLLocationCoordinate2D coords = [self.previousFloorplan pointToCoordinate:point];
[weakSelf.delegate sendPointToCoordinate:coords];
} else {

// Fetches new floorplan information and calls sendPointToCoordinate to send the data to Cordova and Javcascript.
[self.resourceManager fetchFloorPlanWithId:floorplanId andCompletion:^(IAFloorPlan *floorplan, NSError *error) {
if (error) {
Expand All @@ -228,7 +228,7 @@ - (void)getPointToCoordinate:(NSString*)floorplanId andPoint: (CGPoint) point
}*/
return;
}

NSLog(@"getPointToCoordinate: fetched floorplan with id: %@", floorplan.floorPlanId);
CLLocationCoordinate2D coords = [floorplan pointToCoordinate:point];
self.previousFloorplan = floorplan;
Expand Down Expand Up @@ -256,7 +256,7 @@ - (void)fetchFloorplanWithId:(NSString*)floorplanId
}
return;
}

NSLog(@"fetched floorplan with id: %@", floorplanId);
if ([weakSelf.delegate respondsToSelector:@selector(location:withFloorPlan:)]) {
[weakSelf.delegate location:weakSelf withFloorPlan:floorplan];
Expand All @@ -265,11 +265,20 @@ - (void)fetchFloorplanWithId:(NSString*)floorplanId
}];
}

- (void)valueForDistanceFilter:(double*)distance
- (void)valueForDistanceFilter:(float*)distance
{
self.manager.distanceFilter = *(distance);
}

- (float)fetchFloorCertainty
{
return [IALocationManager sharedInstance].location.floor.certainty;
}

- (NSString *)fetchTraceId
{
return [[IALocationManager sharedInstance].extraInfo objectForKey:kIATraceId];
}

#pragma mark Supporting methods
/**
Expand Down
6 changes: 4 additions & 2 deletions src/ios/IndoorLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef NSUInteger IndoorLocationStatus;

// simple object to keep track of location information
@interface IndoorRegionInfo : NSObject {

}
@property (nonatomic, assign) IndoorLocationTransitionType regionStatus;
@property (nonatomic,strong) IARegion *region;
Expand All @@ -38,7 +38,7 @@ typedef NSUInteger IndoorLocationStatus;
@end


@interface IndoorLocation : CDVPlugin{
@interface IndoorLocation : CDVPlugin{
}

@property (nonatomic, strong) CLLocationManager* locationManager;
Expand All @@ -58,5 +58,7 @@ typedef NSUInteger IndoorLocationStatus;
- (void)sendCoordinateToPoint:(CGPoint)point;
- (void)sendPointToCoordinate:(CLLocationCoordinate2D)coords;
- (void)setDistanceFilter:(CDVInvokedUrlCommand*)command;
- (void)getFloorCertainty:(CDVInvokedUrlCommand*)command;
- (void)getTraceId:(CDVInvokedUrlCommand*)command;

@end
Loading

0 comments on commit 134e447

Please sign in to comment.