You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.4 KiB
41 lines
1.4 KiB
import 'package:geolocator/geolocator.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'dart:convert';
|
|
import 'dart:async';
|
|
import '../main.dart';
|
|
|
|
class Location {
|
|
static Future<String> sendCurrentLocation() async {
|
|
Uri uri = Uri.parse("http://89.83.53.34/phpmyadmin/dafldev/insert.php");
|
|
LocationPermission permission;
|
|
permission = await Geolocator.checkPermission();
|
|
if (permission == LocationPermission.denied) {
|
|
permission = await Geolocator.requestPermission();
|
|
if (permission == LocationPermission.deniedForever) {
|
|
//faire l'interface gra pour gérer ça
|
|
return Future.error('Location Not Available');
|
|
}
|
|
}
|
|
String actualUser = MyApp.controller.currentUser.usernameDafl;
|
|
String actualSong = await MyApp.api.getCurrentlyPlayingTrack();
|
|
Position current = await Geolocator.getCurrentPosition();
|
|
await http.post(uri, body: {
|
|
"id": actualUser.toString(),
|
|
"latitude": current.latitude.toString(),
|
|
"longitude": current.longitude.toString(),
|
|
"idMusic": actualSong.toString(),
|
|
});
|
|
return getData();
|
|
}
|
|
|
|
static Future<String> getData() async {
|
|
String actualUser = MyApp.controller.currentUser.usernameDafl;
|
|
Uri uri = Uri.parse("http://89.83.53.34/phpmyadmin/dafldev/distance.php");
|
|
http.Response response = await http.post(uri, body: {
|
|
"id": actualUser,
|
|
});
|
|
var data = jsonDecode(response.body);
|
|
return data.toString();
|
|
}
|
|
}
|