mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-12-22 21:45:48 +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/utils/endpoints.dart' as Endpoints;
|
||||
|
||||
|
||||
class MapService{
|
||||
Future<LatitudeLongitude> getLastLocation(deviceId) async {
|
||||
Future<LatitudeLongitude> getPetLastLocation(deviceId) async {
|
||||
final response = await http.get(
|
||||
Uri.parse(Endpoints.getLastLocation),
|
||||
headers: <String, String>{
|
||||
|
@ -14,7 +13,6 @@ class MapService{
|
|||
'deviceid': deviceId,
|
||||
},
|
||||
);
|
||||
print(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 {
|
||||
_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();
|
||||
print(myLocation.latitude);
|
||||
setState(() {
|
||||
_markers.clear();
|
||||
if (lastLocation.latitude!=-1.0 && lastLocation.latitude!=-1.0){
|
||||
final petMarker = Marker(
|
||||
markerId: MarkerId("pet_location"),
|
||||
position: LatLng(lastLocation.latitude, lastLocation.longitude),
|
||||
infoWindow: InfoWindow(
|
||||
title: "Pet location",
|
||||
),
|
||||
);
|
||||
_markers["pet_location"] = petMarker;
|
||||
}
|
||||
final petMarker = Marker(
|
||||
markerId: MarkerId("pet_location"),
|
||||
position: LatLng(lastLocation.latitude, lastLocation.longitude),
|
||||
infoWindow: InfoWindow(title: "Pet location"));
|
||||
|
||||
if (myLocation.latitude!=-1.0 && myLocation.longitude!=-1.0){
|
||||
final myMarker = Marker(
|
||||
markerId: MarkerId("my_location"),
|
||||
position: LatLng(myLocation.latitude, myLocation.longitude),
|
||||
infoWindow: InfoWindow(
|
||||
title: "My location",
|
||||
),
|
||||
);
|
||||
_markers["my_location"] = myMarker;
|
||||
}
|
||||
final myMarker = Marker(
|
||||
markerId: MarkerId("my_location"),
|
||||
position: LatLng(myLocation.latitude, myLocation.longitude),
|
||||
infoWindow: InfoWindow(title: "My location"));
|
||||
|
||||
_markers["pet_location"] = petMarker;
|
||||
_markers["my_location"] = myMarker;
|
||||
_mapController.animateCamera(CameraUpdate.newLatLng(LatLng(myLocation.latitude, myLocation.longitude)));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue