Venues from server #44
233
lib/Map.dart
233
lib/Map.dart
@ -1,7 +1,10 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_applicationdemo/WeatherData.dart';
|
||||
import 'package:flutter_applicationdemo/WebScraper.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'dart:async';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:flutter_google_places/flutter_google_places.dart';
|
||||
@ -12,13 +15,13 @@ import 'package:geolocator/geolocator.dart';
|
||||
|
||||
import 'package:flutter_applicationdemo/login/User.dart';
|
||||
import 'SettingsPage.dart';
|
||||
import 'WeatherData.dart';
|
||||
import 'venuePage.dart';
|
||||
import 'Venue.dart';
|
||||
import 'globals.dart' as globals;
|
||||
|
||||
|
||||
import 'globals.dart' as globals;
|
||||
|
||||
|
||||
class Map extends StatefulWidget {
|
||||
@override
|
||||
State<Map> createState() => MapState();
|
||||
@ -28,20 +31,18 @@ const kGoogleApiKey = "AIzaSyAUmhd6Xxud8SwgDxJ4LlYlcntm01FGoSk";
|
||||
|
||||
final homeSacffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
|
||||
class MapState extends State<Map> {
|
||||
bool _bottomSheetIsOpen = false;
|
||||
|
||||
Future getMerkerData() async {
|
||||
var url = Uri.parse('https://openstreetgs.stockholm.se/geoservice/api/b8e20fd7-5654-465e-8976-35b4de902b41/wfs?service=wfs&version=1.1.0&request=GetFeature&typeNames=od_gis:Markupplatelse&srsName=EPSG:4326&outputFormat=json');
|
||||
/* Future getMerkerData() async {
|
||||
var url = Uri.parse(
|
||||
'https://openstreetgs.stockholm.se/geoservice/api/b8e20fd7-5654-465e-8976-35b4de902b41/wfs?service=wfs&version=1.1.0&request=GetFeature&typeNames=od_gis:Markupplatelse&srsName=EPSG:4326&outputFormat=json');
|
||||
var response = await http.get(url);
|
||||
|
||||
print('Response status: ${response.statusCode}');
|
||||
// print('Response body: ${response.body.toString()}');
|
||||
var jsonData = jsonDecode(response.body);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
final Completer<GoogleMapController> _controller = Completer();
|
||||
|
||||
@ -49,7 +50,7 @@ class MapState extends State<Map> {
|
||||
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
|
||||
static const CameraPosition _kGooglePlex = CameraPosition(
|
||||
static const CameraPosition _stockholmCity = CameraPosition(
|
||||
target: LatLng(59.325027, 18.068516),
|
||||
zoom: 14.4746,
|
||||
);
|
||||
@ -63,11 +64,28 @@ class MapState extends State<Map> {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
initialize() {
|
||||
List<Venue> allVenues = globals.VENUES;
|
||||
for (var venue in allVenues) {
|
||||
Marker marker = Marker(
|
||||
markerId: MarkerId(venue.venueID.toString()),
|
||||
position: venue.position,
|
||||
/*infoWindow: InfoWindow(
|
||||
title: venue.venueName,
|
||||
snippet: venue.venueAddress,
|
||||
),*/
|
||||
// onTap: () => createBottomSheet(venue.venueName),
|
||||
onTap: () => createBottomDrawer(venue),
|
||||
icon: venue.drawIconColor(),
|
||||
);
|
||||
markersList.add(marker);
|
||||
}
|
||||
}
|
||||
|
||||
void createBottomSheet(String venueName) async {
|
||||
var webScraper = WebScraper();
|
||||
await webScraper.getWebsiteData(venueName);
|
||||
Scaffold.of(context).showBottomSheet<void>(
|
||||
((context) {
|
||||
Scaffold.of(context).showBottomSheet<void>(((context) {
|
||||
return Container(
|
||||
height: 420,
|
||||
color: Colors.white,
|
||||
@ -83,29 +101,12 @@ class MapState extends State<Map> {
|
||||
Container(
|
||||
child: Text(webScraper.openingHoursThisWeek.length.toString()),
|
||||
),
|
||||
|
||||
],
|
||||
)
|
||||
),
|
||||
);
|
||||
})
|
||||
)),
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
initialize() {
|
||||
List<Venue> allVenues = globals.VENUES;
|
||||
for(var venue in allVenues) {
|
||||
Marker marker = Marker(
|
||||
markerId: MarkerId(venue.venueID.toString()),
|
||||
position: venue.position,
|
||||
onTap: () => createBottomSheet(venue.venueName),
|
||||
icon: venue.drawIconColor(),
|
||||
);
|
||||
markersList.add(marker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<LocationData> _getLocationPermission() async {
|
||||
Location location = Location();
|
||||
|
||||
@ -148,6 +149,7 @@ class MapState extends State<Map> {
|
||||
final screens = [
|
||||
Map(),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -155,8 +157,10 @@ class MapState extends State<Map> {
|
||||
key: homeSacffoldKey,
|
||||
//leading: IconButton(icon: Icon(Icons.search), onPressed:() {},),
|
||||
actions: <Widget>[
|
||||
IconButton(icon: const Icon(Icons.search), onPressed:() {
|
||||
},),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
title: TextFormField(
|
||||
controller: _searchController,
|
||||
@ -172,25 +176,26 @@ class MapState extends State<Map> {
|
||||
children: [
|
||||
GoogleMap(
|
||||
mapType: MapType.normal,
|
||||
initialCameraPosition: _kGooglePlex,
|
||||
myLocationEnabled: true,
|
||||
initialCameraPosition: _stockholmCity,
|
||||
markers: markersList.map((e) => e).toSet(),
|
||||
onMapCreated: (GoogleMapController controller) {
|
||||
_controller.complete(controller);
|
||||
},
|
||||
onTap: (LatLng) {
|
||||
closeBottomSheetIfOpen();
|
||||
},
|
||||
),
|
||||
// ElevatedButton(onPressed: () {} //_handelPressButton
|
||||
// ,child: const Text("Search Placses"))
|
||||
],
|
||||
),
|
||||
|
||||
floatingActionButton: Padding(
|
||||
padding: const EdgeInsets.only(top: 100.0),
|
||||
child: FloatingActionButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SettingsPage()));
|
||||
Navigator.push(context,
|
||||
MaterialPageRoute(builder: (context) => const SettingsPage()));
|
||||
},
|
||||
backgroundColor: Colors.purple,
|
||||
child: const Icon(Icons.filter_alt),
|
||||
@ -200,15 +205,17 @@ class MapState extends State<Map> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Future<void> _gotoLocation(double lat, double lng) async {
|
||||
final GoogleMapController controller = await _controller.future;
|
||||
controller.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(target: LatLng(lat,lng), zoom: 15)));
|
||||
controller.animateCamera(CameraUpdate.newCameraPosition(
|
||||
CameraPosition(target: LatLng(lat, lng), zoom: 15)));
|
||||
}
|
||||
|
||||
Widget _boxes(double lat, double lng, String resturantName) {
|
||||
return GestureDetector(
|
||||
onTap: () { _gotoLocation(lat, lng);},
|
||||
onTap: () {
|
||||
_gotoLocation(lat, lng);
|
||||
},
|
||||
child: Container(
|
||||
child: FittedBox(
|
||||
child: Material(
|
||||
@ -224,9 +231,8 @@ class MapState extends State<Map> {
|
||||
height: 200,
|
||||
child: ClipRRect(
|
||||
borderRadius: new BorderRadius.circular(24.0),
|
||||
child: const Image(
|
||||
image: AssetImage('assets/images/bild.png')
|
||||
),
|
||||
child:
|
||||
const Image(image: AssetImage('assets/images/bild.png')),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
@ -238,8 +244,7 @@ class MapState extends State<Map> {
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
@ -252,6 +257,139 @@ class MapState extends State<Map> {
|
||||
zoom: 14.4746)));
|
||||
}
|
||||
|
||||
createBottomDrawer(Venue venue) async {
|
||||
// Position? position = await Geolocator.getLastKnownPosition();
|
||||
// double bar = Geolocator.bearingBetween(position != null? position.latitude : 0, position != null? position.longitude : 0, venue.position.latitude, venue.position.longitude);
|
||||
_bottomSheetIsOpen = true;
|
||||
Scaffold.of(context).showBottomSheet<void>(((context) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => VenuePage(venue)),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
height: 250,
|
||||
color: const Color(0xFFF5F5F5),
|
||||
child: Center(
|
||||
child: Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
columnCoveringNameAndAddress(venue),
|
||||
columnCoveringRating(),
|
||||
],
|
||||
),
|
||||
),
|
||||
columnHandlingCloseButton(context),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text('Weather: \t\t'),
|
||||
globals.forecast.getCurrentWeatherIcon(),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text('– ' + globals.forecast.getCurrentWeatherStatus()),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const Text('Distance:'),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
Column columnHandlingCloseButton(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
child: const Text('Close'),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
_bottomSheetIsOpen = false;
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Column columnCoveringRating() {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
'Rating',
|
||||
style: GoogleFonts.robotoCondensed(
|
||||
textStyle: const TextStyle(
|
||||
color: Colors.black87,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Column columnCoveringNameAndAddress(Venue venue) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
venue.venueName,
|
||||
style: GoogleFonts.roboto(
|
||||
textStyle: const TextStyle(
|
||||
color: Colors.black87,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 24,
|
||||
)),
|
||||
),
|
||||
Text(
|
||||
venue.venueAddress + ' ' + venue.venueStreetNo,
|
||||
style: GoogleFonts.roboto(
|
||||
textStyle: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w200,
|
||||
fontSize: 18,
|
||||
)),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
closeBottomSheetIfOpen() {
|
||||
print(_bottomSheetIsOpen);
|
||||
if (_bottomSheetIsOpen) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
|
||||
/* Future<void> _handelPressButton() async {
|
||||
|
||||
Prediction? p = await PlacesAutocomplete.show(
|
||||
@ -291,4 +429,3 @@ class MapState extends State<Map> {
|
||||
googleMapController.animateCamera(CameraUpdate.newLatLngZoom(LatLng(lat,lng), 14.0));
|
||||
}*/
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ class ShadowDetector {
|
||||
|
||||
List<Venue> get listWithVenuesInShade => venuesInShade; //Get all venues with their shadow status updated.
|
||||
|
||||
void evaluateShadowsForOneVenue (Venue venue) async {
|
||||
Future evaluateShadowsForOneVenue (Venue venue) async {
|
||||
LatLng pos= venue.position;
|
||||
final lat = pos.latitude.toString();
|
||||
final lng = pos.longitude.toString();
|
||||
|
@ -25,12 +25,12 @@ class Venue {
|
||||
LatLng tempPosition = LatLng(double.parse(splitArr[1]), double.parse(splitArr[0]));
|
||||
|
||||
|
||||
print(splitArr[0].toString() + ' : ' + splitArr[1].toString());
|
||||
/* print(splitArr[0].toString() + ' : ' + splitArr[1].toString());
|
||||
print('Coordinates: ' + tempCoordinates);
|
||||
print('Parsed: ' + double.parse(splitArr[0]).toString());
|
||||
print(LatLng(double.parse(splitArr[1]), double.parse(splitArr[0])));
|
||||
print(tempAddress + tempName);
|
||||
print(tempPosition.latitude.toString() + " " + splitArr[0]);
|
||||
print(tempPosition.latitude.toString() + " " + splitArr[0]);*/
|
||||
|
||||
// print('Json-Object:');
|
||||
// print(json);
|
||||
@ -91,7 +91,7 @@ class Venue {
|
||||
String toString() {
|
||||
return 'ID: ' +
|
||||
venueID.toString() +
|
||||
' ' +
|
||||
', ' +
|
||||
'name: ' +
|
||||
venueName +
|
||||
', ' +
|
||||
|
@ -140,4 +140,7 @@ class WeatherData {
|
||||
return const FaIcon(FontAwesomeIcons.times);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
import 'package:flutter_applicationdemo/WeatherData.dart';
|
||||
|
||||
import 'Venue.dart';
|
||||
import 'package:flutter_applicationdemo/login/User.dart';
|
||||
import '../login/User.dart';
|
||||
@ -19,6 +21,7 @@ Color TEXTCOLOR = const Color.fromARGB(255, 79, 98, 114);
|
||||
Color SHADOWCOLOR = const Color.fromARGB(255, 0, 0, 0);
|
||||
Color TEXTWHITE = const Color.fromARGB(0, 0, 0, 0);
|
||||
late List<Venue> VENUES = [];
|
||||
late WeatherData forecast;
|
||||
|
||||
Venue? getVenueByID(int searchedVenueID){
|
||||
for(var V in VENUES){
|
||||
|
@ -13,6 +13,7 @@ import 'package:provider/provider.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'Map.dart';
|
||||
import 'WeatherData.dart';
|
||||
import 'HomePage.dart';
|
||||
import 'Venue.dart';
|
||||
import 'mysql.dart';
|
||||
@ -24,10 +25,29 @@ void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp();
|
||||
await loadAllVenues();
|
||||
await fetchWeather();
|
||||
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
Future fetchWeather() async {
|
||||
WeatherData tempWeather = WeatherData(0, 0);
|
||||
Uri weatherDataURI = Uri.parse(
|
||||
'https://group-4-75.pvt.dsv.su.se/target/weather-0.0.2-SNAPSHOT.war/weather');
|
||||
|
||||
final response = await http.get(weatherDataURI);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = json.decode(response.body);
|
||||
tempWeather = WeatherData.fromJson(data);
|
||||
print(data);
|
||||
|
||||
globals.forecast = tempWeather;
|
||||
} else {
|
||||
throw const HttpException("Problem fetching the weather data");
|
||||
}
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -46,32 +66,39 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
|
||||
Future loadAllVenues() async {
|
||||
|
||||
Uri venueDataURI = Uri.parse(
|
||||
'https://group-4-75.pvt.dsv.su.se/target/weather-0.0.4-SNAPSHOT.war/venue');
|
||||
|
||||
final response = await http.get(venueDataURI);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = json.decode(response.body);
|
||||
var _allVenuesTemp = [];
|
||||
addVenues(response);
|
||||
|
||||
addValidVenues(data, _allVenuesTemp);
|
||||
|
||||
var count = 0;
|
||||
for (Venue vdata in _allVenuesTemp) {
|
||||
count++;
|
||||
//print(count.toString() + ': ' + vdata.toString());
|
||||
globals.VENUES.add(vdata);
|
||||
}
|
||||
// var sd = ShadowDetector();
|
||||
// await sd.evaluateShadowsForAllVenues(seventyFiveVenues);
|
||||
} else {
|
||||
throw const HttpException("Problem fetching the weather data");
|
||||
}
|
||||
}
|
||||
|
||||
void addVenues(http.Response response) {
|
||||
var data = json.decode(response.body);
|
||||
var _allVenuesTemp = [];
|
||||
|
||||
addValidVenues(data, _allVenuesTemp);
|
||||
|
||||
for (Venue venue in _allVenuesTemp) {
|
||||
globals.VENUES.add(venue);
|
||||
}
|
||||
}
|
||||
|
||||
void addValidVenues(data, List<dynamic> _allVenuesTemp) {
|
||||
for (var i = 0; i < data.values.first.length; i++) {
|
||||
if (!data.values.first[i]['name'].contains('©') &&
|
||||
if (data.values.first[i]['name'] == null) {
|
||||
continue;
|
||||
} else if (data.values.first[i]['address'].contains('null')) {
|
||||
continue;
|
||||
} else if (!data.values.first[i]['name'].contains('©') &&
|
||||
!data.values.first[i]['name'].contains('¶') &&
|
||||
!data.values.first[i]['name'].contains('¥') &&
|
||||
!data.values.first[i]['name'].contains('Ã') &&
|
||||
@ -86,23 +113,3 @@ void addValidVenues(data, List<dynamic> _allVenuesTemp) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Future<void> loadAllVenues() async {
|
||||
globals.VENUES = [];
|
||||
var db = mysql();
|
||||
await db.getConnection().then((conn) async {
|
||||
String sql =
|
||||
"select venueName, venueID, latitude, longitude from maen0574.venue";
|
||||
await conn.query(sql).then((results) {
|
||||
for (var row in results) {
|
||||
globals.VENUES.add(Venue(
|
||||
row[0], row[1], VenueType.restaurant, LatLng(row[2], row[3])));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var sd = ShadowDetector();
|
||||
await sd.evaluateShadowsForAllVenues(globals.VENUES);
|
||||
}
|
||||
*/
|
||||
|
@ -165,6 +165,8 @@ class _VenuePageState extends State<VenuePage> {
|
||||
|
||||
_VenuePageState(this.venue);
|
||||
|
||||
|
||||
|
||||
validateAndGetImageLink() {
|
||||
if (imageLink == '') {
|
||||
return 'https://live.staticflickr.com/6205/6081773215_19444220b6_b.jpg';
|
||||
|
Loading…
x
Reference in New Issue
Block a user