I try to build an app using geolocation services
here is the code:
import 'package:brew_two/services/auth.dart';
import 'package:flutter/material.dart';
import 'package:geolocation/geolocation.dart';
import 'package:flutter_map/flutter_map.dart';
class Home extends StatelessWidget {
MapController controller = new MapController();
getPermission() async {
final GeolocationResult result =
await Geolocation.requestLocationPermission(
const LocationPermission(
android: LocationPermissionAndroid.fine,
ios : LocationPermissionIOS.always));
return result;
}
getLocation() {
return getPermission().then((result) async {
if(result.isSuccessful){
final coords = await Geolocation.currentLocation(
accuracy: LocationAccuracy.best);
}
});
}
buildMap(){
getLocation().then((response) {
if(response.isSuccessful){
response.listen((value){
controller.move(
new LatLng(value.location.lattitude, value.location.longtiude),
15.0);
});
}
});
}
final AuthService _auth = AuthService();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.brown[50],
appBar: AppBar(
title: Text('Brew Crew'),
backgroundColor: Colors.brown[400],
elevation: 0.0,
actions: <Widget>[
FlatButton.icon(
onPressed: () async {
await _auth.signOut();
},
icon: Icon(Icons.person),
label: Text('Logout'))
],
),
body: new FlutterMap(
mapController: controller,
options: new MapOptions(center: buildMap(), minZoom: 5.0),
layers: [
new TileLayerOptions(
urlTemplate:
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: ['a', 'b', 'c']),
]),
);
}
}
but I face the following problems here:
await Geolocation.requestLocationPermission(
const LocationPermission(
android: LocationPermissionAndroid.fine,
ios : LocationPermissionIOS.always));
Too many positional arguments: 0 expected, but 1 found. Try removing the extra positional arguments, or specifying the name for named arguments.
and the other problem with LatLng function:
new LatLng(value.location.lattitude, value.location.longtiude),
The constructor returns type 'dynamic' that isn't of expected type 'LatLng'. Undefined class 'LatLng'. Try changing the name to the name of an existing class, or creating a class with the name 'LatLng'.
Can someone help me please?
For the LatLng issue import the latlong pacakge
import "package:latlong/latlong.dart";
For the permission issue, use permissions as given below
getPermission() async {
final GeolocationResult result =
await Geolocation.requestLocationPermission(
permission: const LocationPermission(
android: LocationPermissionAndroid.fine,
ios: LocationPermissionIOS.always));
return result;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.