|
|
@ -2,41 +2,42 @@ import 'package:geolocator/geolocator.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import '../main.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../../main.dart';
|
|
|
|
class Location {
|
|
|
|
import '../../model/spot.dart';
|
|
|
|
static Future<Map<String, dynamic>> sendCurrentLocation() async {
|
|
|
|
|
|
|
|
|
|
|
|
class Area {
|
|
|
|
|
|
|
|
late List<Spot> spots;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sendCurrentLocation() async {
|
|
|
|
|
|
|
|
Uri uri = Uri.parse("http://89.83.53.34/phpmyadmin/dafldev/insert.php");
|
|
|
|
Uri uri = Uri.parse("http://89.83.53.34/phpmyadmin/dafldev/insert.php");
|
|
|
|
LocationPermission permission;
|
|
|
|
LocationPermission permission;
|
|
|
|
permission = await Geolocator.checkPermission();
|
|
|
|
permission = await Geolocator.checkPermission();
|
|
|
|
if (permission == LocationPermission.denied) {
|
|
|
|
if (permission == LocationPermission.denied) {
|
|
|
|
permission = await Geolocator.requestPermission();
|
|
|
|
permission = await Geolocator.requestPermission();
|
|
|
|
if (permission == LocationPermission.deniedForever) {
|
|
|
|
if (permission == LocationPermission.deniedForever) {
|
|
|
|
//TODO : handle this case
|
|
|
|
//faire l'interface gra pour gérer ça
|
|
|
|
|
|
|
|
return Future.error('Location Not Available');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String actualUser = MyApp.controller.getIdSpotify();
|
|
|
|
String actualUser = MyApp.controller.currentUser.usernameDafl;
|
|
|
|
String actualSong = await MyApp.controller.getCurrentMusic();
|
|
|
|
String actualSong = await MyApp.api.getCurrentlyPlayingTrack();
|
|
|
|
Position current = await Geolocator.getCurrentPosition();
|
|
|
|
Position current = await Geolocator.getCurrentPosition();
|
|
|
|
await http.post(uri, body: {
|
|
|
|
await http.post(uri, body: {
|
|
|
|
"id": actualUser,
|
|
|
|
"id": actualUser.toString(),
|
|
|
|
"latitude": current.latitude.toString(),
|
|
|
|
"latitude": current.latitude.toString(),
|
|
|
|
"longitude": current.longitude.toString(),
|
|
|
|
"longitude": current.longitude.toString(),
|
|
|
|
"idMusic": actualSong
|
|
|
|
"idMusic": actualSong.toString(),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return getData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getData() async {
|
|
|
|
static Future<Map<String, dynamic>> getData() async {
|
|
|
|
String actualUser = MyApp.controller.getIdDafl().toString();
|
|
|
|
Map<String, dynamic> spot = {};
|
|
|
|
Uri uri = Uri.parse("http://89.83.53.34/phpmyadmin/dafldev/distance.php");
|
|
|
|
String actualUser = MyApp.controller.currentUser.usernameDafl;
|
|
|
|
|
|
|
|
Uri uri = Uri.parse("codefirst.iut.uca.fr/dorian.hodin/dafl_music:latest/distance.php");
|
|
|
|
http.Response response = await http.post(uri, body: {
|
|
|
|
http.Response response = await http.post(uri, body: {
|
|
|
|
"id": actualUser,
|
|
|
|
"id": actualUser,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var data = jsonDecode(response.body);
|
|
|
|
var data = jsonDecode(response.body);
|
|
|
|
data.forEach((s) => spots.add(Spot(s['user'], s['music'])));
|
|
|
|
data.forEach((s)=> spot.putIfAbsent(s['user'], () => s['music']));
|
|
|
|
|
|
|
|
return spot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|