mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-11-10 01:35:50 +00:00
Code refractoring
This commit is contained in:
parent
6464161b34
commit
c929242804
|
@ -4,9 +4,8 @@ import 'package:http/http.dart' as http;
|
||||||
import 'package:leg_barkr_app/model/latitude_longitude.dart';
|
import 'package:leg_barkr_app/model/latitude_longitude.dart';
|
||||||
import 'package:leg_barkr_app/utils/endpoints.dart' as Endpoints;
|
import 'package:leg_barkr_app/utils/endpoints.dart' as Endpoints;
|
||||||
|
|
||||||
|
|
||||||
class MapService{
|
class MapService{
|
||||||
Future<LatitudeLongitude> getLastLocation(deviceId) async {
|
Future<LatitudeLongitude> getPetLastLocation(deviceId) async {
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse(Endpoints.getLastLocation),
|
Uri.parse(Endpoints.getLastLocation),
|
||||||
headers: <String, String>{
|
headers: <String, String>{
|
||||||
|
@ -14,7 +13,6 @@ class MapService{
|
||||||
'deviceid': deviceId,
|
'deviceid': deviceId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
print(response.body);
|
|
||||||
return LatitudeLongitude.fromJson(jsonDecode(response.body));
|
return LatitudeLongitude.fromJson(jsonDecode(response.body));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class Resources {
|
|
||||||
static final Color primaryColour = Colors.green;
|
|
||||||
static final Color primaryAccentColour = Colors.greenAccent;
|
|
||||||
|
|
||||||
}
|
|
|
@ -15,32 +15,22 @@ class _MapPageState extends State<MapPage> {
|
||||||
|
|
||||||
Future<void> _onMapCreated(GoogleMapController controller) async {
|
Future<void> _onMapCreated(GoogleMapController controller) async {
|
||||||
_mapController = controller;
|
_mapController = controller;
|
||||||
final lastLocation = await MapService().getLastLocation("132-567-001"); // change this.
|
final lastLocation = await MapService().getPetLastLocation("132-567-001"); // change this.
|
||||||
final myLocation = await MapService().getMyLocation();
|
final myLocation = await MapService().getMyLocation();
|
||||||
print(myLocation.latitude);
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_markers.clear();
|
_markers.clear();
|
||||||
if (lastLocation.latitude!=-1.0 && lastLocation.latitude!=-1.0){
|
final petMarker = Marker(
|
||||||
final petMarker = Marker(
|
markerId: MarkerId("pet_location"),
|
||||||
markerId: MarkerId("pet_location"),
|
position: LatLng(lastLocation.latitude, lastLocation.longitude),
|
||||||
position: LatLng(lastLocation.latitude, lastLocation.longitude),
|
infoWindow: InfoWindow(title: "Pet location"));
|
||||||
infoWindow: InfoWindow(
|
|
||||||
title: "Pet location",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
_markers["pet_location"] = petMarker;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myLocation.latitude!=-1.0 && myLocation.longitude!=-1.0){
|
final myMarker = Marker(
|
||||||
final myMarker = Marker(
|
markerId: MarkerId("my_location"),
|
||||||
markerId: MarkerId("my_location"),
|
position: LatLng(myLocation.latitude, myLocation.longitude),
|
||||||
position: LatLng(myLocation.latitude, myLocation.longitude),
|
infoWindow: InfoWindow(title: "My location"));
|
||||||
infoWindow: InfoWindow(
|
|
||||||
title: "My location",
|
_markers["pet_location"] = petMarker;
|
||||||
),
|
_markers["my_location"] = myMarker;
|
||||||
);
|
|
||||||
_markers["my_location"] = myMarker;
|
|
||||||
}
|
|
||||||
_mapController.animateCamera(CameraUpdate.newLatLng(LatLng(myLocation.latitude, myLocation.longitude)));
|
_mapController.animateCamera(CameraUpdate.newLatLng(LatLng(myLocation.latitude, myLocation.longitude)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue