Files
rog_app/lib/services/location_service.dart

164 lines
5.3 KiB
Dart
Raw Normal View History

2022-03-14 13:14:15 +05:30
import 'dart:convert';
2022-07-30 20:42:44 +05:30
import 'package:geojson_vi/geojson_vi.dart';
import 'package:get/get.dart';
2022-03-14 12:28:57 +05:30
import 'package:http/http.dart' as http;
2022-07-30 20:42:44 +05:30
import 'package:rogapp/model/location.dart';
2022-06-14 14:37:59 +05:30
import 'package:rogapp/utils/const.dart';
2022-03-14 12:28:57 +05:30
2022-07-30 20:42:44 +05:30
class LocationService extends GetxService{
Future<LocationService> init() async {
print('$runtimeType ready!');
return this;
}
2022-03-14 12:28:57 +05:30
2022-07-30 20:42:44 +05:30
Future<List<Location>> loadLocations() async {
List<Location> locs = [];
String serverUrl = ConstValues.currentServer();
String url = '${serverUrl}/api/location/';
2022-03-14 12:28:57 +05:30
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
if (response.statusCode == 200) {
2022-07-30 20:42:44 +05:30
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
for(int i=0; i<coll.features.length; i++ ){
GeoJSONFeature? gf = coll.features[i];
if(gf != null){
Location l = Location.fromGeoJSONFeture(gf);
locs.add(l);
}
}
2022-03-14 12:28:57 +05:30
}
2022-07-30 20:42:44 +05:30
return locs;
2022-03-14 12:28:57 +05:30
}
2022-07-30 20:42:44 +05:30
Future<List<Location>> loadLocationsFor(String perfecture, String cat) async {
List<Location> locs = [];
2022-05-12 02:17:08 +05:30
String url = "";
2022-07-30 20:42:44 +05:30
String serverUrl = ConstValues.currentServer();
2022-05-12 02:17:08 +05:30
if(cat.isNotEmpty){
2022-07-30 20:42:44 +05:30
url = '${serverUrl}/api/inperf/?perf=' + perfecture + '&cat=' + cat;
2022-05-12 02:17:08 +05:30
}
else{
2022-07-30 20:42:44 +05:30
url = '${serverUrl}/api/inperf/?perf=' + perfecture;
2022-05-12 02:17:08 +05:30
}
2022-05-18 19:09:26 +05:30
//print("----- url ---- ${url} --- ${cat}");
2022-03-30 16:19:18 +05:30
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
if (response.statusCode == 200) {
2022-07-30 20:42:44 +05:30
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
for(int i=0; i<coll.features.length; i++ ){
GeoJSONFeature? gf = coll.features[i];
if(gf != null){
Location l = Location.fromGeoJSONFeture(gf);
locs.add(l);
}
}
2022-03-30 16:19:18 +05:30
}
2022-07-30 20:42:44 +05:30
return locs;
2022-04-17 11:45:21 +05:30
}
2022-07-30 20:42:44 +05:30
Future<List<Location>> loadLocationsSubFor(String subperfecture, String cat) async {
List<Location> locs = [];
2022-05-12 02:17:08 +05:30
String url = "";
2022-06-14 14:37:59 +05:30
String server_url = ConstValues.currentServer();
2022-05-12 02:17:08 +05:30
if(cat.isNotEmpty){
2022-06-14 14:37:59 +05:30
url = '${server_url}/api/insubperf?subperf=' + subperfecture + '&cat=' + cat;
2022-05-12 02:17:08 +05:30
}
else{
2022-05-18 19:09:26 +05:30
print("------ loading location in sub----");
2022-06-14 14:37:59 +05:30
url = '${server_url}/api/insubperf?subperf=' + subperfecture;
2022-05-12 02:17:08 +05:30
}
2022-04-17 11:45:21 +05:30
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
if (response.statusCode == 200) {
2022-07-30 20:42:44 +05:30
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
for(int i=0; i<coll.features.length; i++ ){
GeoJSONFeature? gf = coll.features[i];
if(gf != null){
Location l = Location.fromGeoJSONFeture(gf);
locs.add(l);
}
}
2022-04-17 11:45:21 +05:30
}
2022-07-30 20:42:44 +05:30
return locs;
2022-03-30 16:19:18 +05:30
}
2022-07-30 20:42:44 +05:30
Future<List<Location>> loadLocationsBound(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3, double lat4, double lon4, String cat) async {
List<Location> locs = [];
2022-05-18 19:09:26 +05:30
String url = "";
2022-06-14 14:37:59 +05:30
String server_url = ConstValues.currentServer();
2022-07-30 20:42:44 +05:30
//print("cat is ----- ${cat}");
2022-05-18 19:09:26 +05:30
if(cat.isNotEmpty){
2022-06-14 14:37:59 +05:30
url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat;
2022-05-18 19:09:26 +05:30
}
else{
2022-06-14 14:37:59 +05:30
url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}';
2022-05-18 19:09:26 +05:30
}
2022-07-30 20:42:44 +05:30
//print("----url --- ${url}");
2022-05-18 19:09:26 +05:30
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
if (response.statusCode == 200) {
2022-07-30 20:42:44 +05:30
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
for(int i=0; i<coll.features.length; i++ ){
GeoJSONFeature? gf = coll.features[i];
if(gf != null){
Location l = Location.fromGeoJSONFeture(gf);
locs.add(l);
}
2022-05-18 19:09:26 +05:30
}
}
2022-07-30 20:42:44 +05:30
return locs;
2022-05-18 19:09:26 +05:30
}
2022-07-30 20:42:44 +05:30
Future<List<Location>> loadCustomLocations(String name, String cat) async {
List<Location> locs = [];
2022-06-06 21:15:58 +05:30
String url = "";
2022-06-14 14:37:59 +05:30
String server_url = ConstValues.currentServer();
2022-06-06 21:15:58 +05:30
print("cat is ----- ${cat}");
if(cat.isNotEmpty){
2022-06-14 14:37:59 +05:30
url = '${server_url}/api/custom_area/?&cat=' + cat;
//url = 'http://localhost:8100/api/customarea?name=${name}&cat=' + cat;
2022-06-06 21:15:58 +05:30
}
else{
2022-06-14 14:37:59 +05:30
url = '${server_url}/api/customarea?name=${name}&';
//url = 'http://localhost:8100/api/customarea?name=${name}&';
2022-06-06 21:15:58 +05:30
}
print("----url --- ${url}");
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
2022-07-30 20:42:44 +05:30
if (response.statusCode == 200) {
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
for(int i=0; i<coll.features.length; i++ ){
GeoJSONFeature? gf = coll.features[i];
if(gf != null){
Location l = Location.fromGeoJSONFeture(gf);
locs.add(l);
}
2022-06-06 21:15:58 +05:30
}
}
2022-07-30 20:42:44 +05:30
return locs;
2022-06-06 21:15:58 +05:30
}
2022-07-30 20:42:44 +05:30
}
2022-06-06 21:15:58 +05:30