2022-02-14 14:40:18 +00:00
|
|
|
import 'dart:convert';
|
2022-02-14 16:59:33 +00:00
|
|
|
import 'package:geolocator/geolocator.dart';
|
2022-02-14 14:40:18 +00:00
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:leg_barkr_app/model/latitude_longitude.dart';
|
|
|
|
import 'package:leg_barkr_app/utils/endpoints.dart' as Endpoints;
|
|
|
|
|
|
|
|
class MapService{
|
2022-02-15 11:52:19 +00:00
|
|
|
Future<LatitudeLongitude> getPetLastLocation(String deviceId, String sessionToken) async {
|
2022-02-14 14:40:18 +00:00
|
|
|
final response = await http.get(
|
|
|
|
Uri.parse(Endpoints.getLastLocation),
|
|
|
|
headers: <String, String>{
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
2022-02-15 11:52:19 +00:00
|
|
|
'Authorization': sessionToken,
|
|
|
|
'Device-ID': deviceId,
|
2022-02-14 14:40:18 +00:00
|
|
|
},
|
|
|
|
);
|
2022-02-15 11:52:19 +00:00
|
|
|
if (response.statusCode == 200){
|
|
|
|
return LatitudeLongitude.fromJson(jsonDecode(response.body));
|
|
|
|
} else {
|
|
|
|
return throw Exception('Pet not found');
|
|
|
|
}
|
2022-02-14 16:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Position> getMyLocation() async{
|
|
|
|
LocationPermission permission;
|
|
|
|
permission = await Geolocator.checkPermission();
|
|
|
|
if (permission == LocationPermission.denied) {
|
|
|
|
permission = await Geolocator.requestPermission();
|
|
|
|
if (permission == LocationPermission.deniedForever) {
|
|
|
|
throw Exception('Location denied');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return await Geolocator.getCurrentPosition();
|
2022-02-14 14:40:18 +00:00
|
|
|
}
|
2022-02-14 16:59:33 +00:00
|
|
|
|
2022-02-14 14:40:18 +00:00
|
|
|
}
|