GeoPoint class final
A point on the earth's surface.
It cannot be persisted as a property on a realm object.
Instead, you must use a custom embedded object with the following structure:
@RealmModel(ObjectType.embeddedObject)
class _Location {
final String type = 'Point';
final List<double> coordinates = const [0, 0];
// The rest of the class is just convenience methods
double get lon => coordinates[0];
set lon(double value) => coordinates[0] = value;
double get lat => coordinates[1];
set lat(double value) => coordinates[1] = value;
GeoPoint toGeoPoint() => GeoPoint(lon: lon, lat: lat);
}
You can then use it as a property on a realm object:
@RealmModel()
class _Restaurant {
@PrimaryKey()
late String name;
_Location? location;
}
For convenience add an extension method on GeoPoint:
extension on GeoPoint {
Location toLocation() {
return Location(coordinates: [lon, lat]);
}
}
to easily convert between GeoPoints and Location
s.
The following may also be useful:
extension on (num, num) {
GeoPoint toGeoPoint() => GeoPoint(lon: $1.toDouble(), lat: $2.toDouble());
Location toLocation() => toGeoPoint().toLocation();
}
- Implemented types
Constructors
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override