Reputation: 49
I'm trying to code an app and I'm loading an Eventplace object from my server with the class. I want to use Isar as my offline database, but I don't know how to filter for the nearest eventplace by lat and lng. Unfortantely I couldn't add LatLng as an embedded Object bc of their is not default constructor. I am just needing a possiblity to filter through the objects by the db and check the distance with Geolocator.distanceBetween(lat, lng, lat2, lng2)
or should i just query through all and filter the list by myself.
final database = isar!.eventplaces;
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:isar/isar.dart';
part 'eventplace.g.dart';
@collection
class Eventplace {
Id? id;
int? city_id;
String? city_name;
float? city_lat;
float? city_lng;
String? name;
String? adress;
String? url;
float? latitude;
float? longitude;
Eventplace({
this.id,
this.city_id,
this.city_name,
this.city_lat,
this.city_lng,
this.name,
this.adress,
this.url,
this.latitude,
this.longitude,
});
LatLng createCityLatLng(){
return LatLng(this.city_lat ?? 0.0, this.city_lng ?? 0.0);
}
LatLng createLatLng(){
return LatLng(this.latitude ?? 0.0, this.longitude ?? 0.0);
}
static toJSON(Eventplace ev){
return {};
}
factory Eventplace.fromJSON(Map<String, dynamic> json){
return Eventplace(
id: json['id'] as int,
city_id: json['city_id'] as int,
city_name: json['city_name'] as String?,
city_lat: json['city_lat'] as float?,
city_lng: json['city_lng'] as float?,
name: json['name'] as String?,
adress: json['adress'] as String?,
url: json['url'] as String?,
latitude: json['latitude'] as float?,
longitude: json['longitude'] as float?,
);
}
}
Upvotes: 0
Views: 76