Using map locations
The TestFairy SDK does not require location permissions and does track location out of the box.
In cases where developers whish to send location information to TestFairy, they will need to add location permissions to their app, and use the code below to call TestFairy.updateLocation. After doing that, location will be presented on a map as part of the session page.
To record locations, you must first add the correct permissions to your application. Depending on your application's needs, you may want to add one or both of the following permissions to your AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Syntax
TestFairy.updateLocation(android.location.Location location)
Code Example
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.testfairy.TestFairy;
public class MainActivity extends AppCompatActivity implements LocationListener {
private LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the location manager
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
// Initialize the location fields
if (location != null) {
onLocationChanged(location);
}
}
@Override
public void onLocationChanged(Location location) {
TestFairy.updateLocation(location);
}
}
To record locations, all you need to do is call the static instance method updateLocation
in the TestFairy
class, passing in a collection of CLLocations
.
Syntax
NSArray<CLLocation *> *locations = ...
[TestFairy updateLocation:locations];
Code Example
#import "TestFairy.h"
@interface NewRunViewController: UIViewController <CLLocationManagerDelegate>
- (void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
}
...
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
[TestFairy updateLocation:locations];
}
@end
Last updated on 2023-06-06