Building apps is not always about doing things from scratch and all by yourself. One should always follow the DRY (Don't Repeat Yourself) and KISS (Keep It Short & Simple) principle. Re-inventing the wheel is not always a good idea when you have well tested components and tools already available off-the-shelf.
For the same purpose, GeoSpark provides various utility methods for our community developers to directly make use of it and just focus on your business logic.
One of our most used utility method is geospark.getCurrentLocation()
Why is it needed ? Why do I need this when GeoSpark SDK itself does it for you based on motion and activity ?
GeoSpark does track the location based on the user movement and activity but sometimes for business critical operations or logic to be performed, apps need the latest location immediately with good accuracy. Ex: Credit Card Fraud Mitigation, Location based authentication, Latest device location which is under tracking.
How to use it?
Very easy:
Android:
Note: Gets the current location of the user. You can set the accuracy from 20 to 100 meters (default is 20).
GeoSpark.getCurrentLocation(this, accuracy,
new GeoSparkLocationCallback(){
@Override
public void location(double latitude, double longitude, double accuracy) {
}
@Override
public void onFailure(GeoSparkError geoSparkError) {
geoSparkError.getErrorCode();
geoSparkError.getErrorMessage();
}
});
iOS (Swift):
Note: Gets the current location of the user. You can set the accuracy from 10 to 100 meters (default is 10).
GeoSpark.getCurrentLocation(accuracy) { (location) in
//location.latitude
//location.longitude
//location.activity
//location.accuracy
//location.userId
}
iOS(Objective-C):
[GeoSpark getCurrentLocation:10:^(GSLocation * location) {
//location.latitude
//location.longitude
//location.activity
//location.accuracy
//location.userId
}];
Hope the above explanation works. In case you face any difficulties, feel free to comment on this thread.