mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-12-22 21:45:48 +00:00
Complete map functionality
This commit is contained in:
parent
5431d765d4
commit
6464161b34
|
@ -1,6 +1,7 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.legbarkr.leg_barkr_app">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<application
|
||||
android:label="leg_barkr_app"
|
||||
android:name="${applicationName}"
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string>This app needs access to location when open.</string>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
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;
|
||||
|
@ -16,6 +16,19 @@ class MapService{
|
|||
);
|
||||
print(response.body);
|
||||
return LatitudeLongitude.fromJson(jsonDecode(response.body));
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -11,17 +11,16 @@ class MapPage extends StatefulWidget {
|
|||
|
||||
class _MapPageState extends State<MapPage> {
|
||||
late GoogleMapController _mapController;
|
||||
|
||||
// This will be changed, to center around the dog (once app reads metrics from the server)
|
||||
final LatLng _center = const LatLng(51.498356, -0.176894);
|
||||
|
||||
final Map<String, Marker> _markers = {};
|
||||
|
||||
Future<void> _onMapCreated(GoogleMapController controller) async {
|
||||
_mapController = controller;
|
||||
final lastLocation = await MapService().getLastLocation("132-567-001"); // change this.
|
||||
final myLocation = await MapService().getMyLocation();
|
||||
print(myLocation.latitude);
|
||||
setState(() {
|
||||
_markers.clear();
|
||||
print(lastLocation.longitude);
|
||||
if (lastLocation.latitude!=-1.0 && lastLocation.latitude!=-1.0){
|
||||
final petMarker = Marker(
|
||||
markerId: MarkerId("pet_location"),
|
||||
position: LatLng(lastLocation.latitude, lastLocation.longitude),
|
||||
|
@ -30,7 +29,19 @@ class _MapPageState extends State<MapPage> {
|
|||
),
|
||||
);
|
||||
_markers["pet_location"] = petMarker;
|
||||
print(_markers["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;
|
||||
}
|
||||
_mapController.animateCamera(CameraUpdate.newLatLng(LatLng(myLocation.latitude, myLocation.longitude)));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -41,8 +52,8 @@ class _MapPageState extends State<MapPage> {
|
|||
body: GoogleMap(
|
||||
onMapCreated: _onMapCreated,
|
||||
initialCameraPosition: CameraPosition(
|
||||
target: _center,
|
||||
zoom: 16.0,
|
||||
target: LatLng(51.5, -0.12),
|
||||
zoom: 12.0,
|
||||
),
|
||||
markers: _markers.values.toSet(),
|
||||
),
|
||||
|
|
58
pubspec.lock
58
pubspec.lock
|
@ -226,6 +226,62 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
geocoding:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: geocoding
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
geocoding_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geocoding_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
geolocator:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: geolocator
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.2.0"
|
||||
geolocator_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geolocator_android
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
geolocator_apple:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geolocator_apple
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1+1"
|
||||
geolocator_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geolocator_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.3"
|
||||
geolocator_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geolocator_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
geolocator_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: geolocator_windows
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.0"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -513,4 +569,4 @@ packages:
|
|||
version: "3.1.0"
|
||||
sdks:
|
||||
dart: ">=2.16.0 <3.0.0"
|
||||
flutter: ">=2.5.0"
|
||||
flutter: ">=2.8.0"
|
||||
|
|
|
@ -42,6 +42,8 @@ dependencies:
|
|||
firebase_core: ^1.12.0
|
||||
firebase_auth: ^3.3.7
|
||||
json_serializable: ^6.1.4
|
||||
geocoding: ^2.0.2
|
||||
geolocator: ^8.2.0
|
||||
|
||||
|
||||
dev_dependencies:
|
||||
|
|
Loading…
Reference in a new issue