declex
declex copied to clipboard
Implement @LocationModel to fetch user location
Implementing @LocationModel, any model can be used to gather the user location from GPS. It is recommended to use Google Fused Api to do this.
Basically, let's say you have a Coordinate object which is used with other API, it can be also used to fetch the location directly:
@LocationModel
@LocalDBModel
public class Coordinate extends com.activeandroid.Model {
@Column
double latitude;
@Column
double longitude;
}
The normal rules for models are followed to inject the user location.
A @UseLocation should be used in the activity or service which will be used to fetch the location, this will create also a default "Location" object which could be used to inject directly the user location (this is a normal model):
@LocationModel
public class Location {
double latitude;
double longitude;
}
Also an annotation @LocationField should be implemented to support the fields customization:
@LocalDBModel
public class Coordinate extends com.activeandroid.Model {
@Column
@LocationField(Latitude)
double myLatitude;
@Column
@LocationField(Longitude)
double myLongitude;
}
See that @LocationField uses ADI to annotate Coordinate object with @LocationModel.
Since @LocationModel will be integrated into the Models objects, it can be simply injected:
@Model
Coordinate coordinate;
Also, similar to any @Model, it could be used to @Populate data to the UI.
This feature should be done after finishing Issue #137