declex icon indicating copy to clipboard operation
declex copied to clipboard

Implement @LocationModel to fetch user location

Open smaugho opened this issue 7 years ago • 1 comments

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.

smaugho avatar May 09 '17 03:05 smaugho

This feature should be done after finishing Issue #137

smaugho avatar May 09 '17 03:05 smaugho