goelocation finished
This commit is contained in:
@@ -14,18 +14,13 @@ class MapViewState extends State<MapView> {
|
|||||||
MenuiServices services = new MenuiServices();
|
MenuiServices services = new MenuiServices();
|
||||||
Position position;
|
Position position;
|
||||||
|
|
||||||
Future<Map<MarkerId, Marker>> createMarkers() async {
|
Future<MarkersAndLocation> createMarkers() async {
|
||||||
Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
|
Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
|
||||||
Position position = await Geolocator.getCurrentPosition(
|
Position position = await Geolocator.getCurrentPosition(
|
||||||
desiredAccuracy: LocationAccuracy.high);
|
desiredAccuracy: LocationAccuracy.high);
|
||||||
setState(() {
|
LatLng location = new LatLng(position.latitude, position.longitude);
|
||||||
position = position;
|
List<Restaurant> restaurants = await services.fetchRestaurantsByLocation(
|
||||||
});
|
position.latitude, position.longitude);
|
||||||
print('position is set');
|
|
||||||
/* List<Restaurant> restaurants = await services.fetchRestaurantsByLocation(
|
|
||||||
position.latitude, position.longitude, 1000); */
|
|
||||||
List<Restaurant> restaurants =
|
|
||||||
await services.fetchRestaurantsByLocation(20.60912, 52.87728);
|
|
||||||
if (restaurants.isNotEmpty) {
|
if (restaurants.isNotEmpty) {
|
||||||
for (Restaurant thisRestaurant in restaurants) {
|
for (Restaurant thisRestaurant in restaurants) {
|
||||||
final MarkerId markerId = MarkerId(thisRestaurant.name);
|
final MarkerId markerId = MarkerId(thisRestaurant.name);
|
||||||
@@ -40,37 +35,45 @@ class MapViewState extends State<MapView> {
|
|||||||
markers[markerId] = marker;
|
markers[markerId] = marker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return markers;
|
return new MarkersAndLocation(markers: markers, coordinates: location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: FutureBuilder<Map<MarkerId, Marker>>(
|
body: FutureBuilder<MarkersAndLocation>(
|
||||||
future: createMarkers(),
|
future: createMarkers(),
|
||||||
builder: (BuildContext context,
|
builder:
|
||||||
AsyncSnapshot<Map<MarkerId, Marker>> snapshot) {
|
(BuildContext context, AsyncSnapshot<MarkersAndLocation> snapshot) {
|
||||||
Map<MarkerId, Marker> markers = snapshot.data;
|
MarkersAndLocation data = snapshot.data;
|
||||||
List<Widget> children;
|
Widget child;
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
final CameraPosition _initialPosition = CameraPosition(
|
final CameraPosition _initialPosition = CameraPosition(
|
||||||
target: LatLng(20, 58),
|
target: data.coordinates,
|
||||||
zoom: 16,
|
zoom: 14,
|
||||||
);
|
);
|
||||||
children = <Widget>[
|
child = GoogleMap(
|
||||||
GoogleMap(
|
|
||||||
mapType: MapType.normal,
|
mapType: MapType.normal,
|
||||||
initialCameraPosition: _initialPosition,
|
initialCameraPosition: _initialPosition,
|
||||||
onMapCreated: (GoogleMapController controller) {
|
onMapCreated: (GoogleMapController controller) {
|
||||||
_controller.complete(controller);
|
_controller.complete(controller);
|
||||||
},
|
},
|
||||||
markers: Set<Marker>.of(markers.values),
|
markers: Set<Marker>.of(data.markers.values),
|
||||||
),
|
);
|
||||||
];
|
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
children = <Widget>[Text('error')];
|
child = Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [Text("error...")],
|
||||||
|
),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
children = <Widget>[
|
child = Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
SizedBox(
|
SizedBox(
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
width: 60,
|
width: 60,
|
||||||
@@ -80,15 +83,11 @@ class MapViewState extends State<MapView> {
|
|||||||
padding: EdgeInsets.only(top: 16),
|
padding: EdgeInsets.only(top: 16),
|
||||||
child: Text('Awaiting result...'),
|
child: Text('Awaiting result...'),
|
||||||
)
|
)
|
||||||
];
|
],
|
||||||
}
|
|
||||||
return Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: children,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
return child;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
floatingActionButton: Padding(
|
floatingActionButton: Padding(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import './settings.dart';
|
import './settings.dart';
|
||||||
@@ -452,3 +453,10 @@ class MenuiWorkingHours {
|
|||||||
MenuiWorkingHours(
|
MenuiWorkingHours(
|
||||||
this.pn, this.wt, this.sr, this.cz, this.pt, this.sb, this.nd);
|
this.pn, this.wt, this.sr, this.cz, this.pt, this.sb, this.nd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MarkersAndLocation {
|
||||||
|
final Map<MarkerId, Marker> markers;
|
||||||
|
final LatLng coordinates;
|
||||||
|
|
||||||
|
MarkersAndLocation({@required this.markers, @required this.coordinates});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user