【发布时间】:2020-12-07 06:31:05
【问题描述】:
我正在尝试在我的 Google 地图上显示当前位置。我已经做了一切,但它不起作用。它仍然显示 google plex 位置 Lat 37.42 , -112.08 我尝试在我的物理设备上运行 apk,我添加了权限。又在网上查了一些文章,需要帮助。
这是我的代码
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
void main() => runApp(App());
class App extends StatefulWidget {
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
String _locationMessage = "";
void _getCurrentLocation() async {
final position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
print(position);
setState(() {
_locationMessage = "${position.latitude}, ${position.longitude}";
});
}
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
appBar: AppBar(
title: Text("Location Services")
),
body: Align(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(_locationMessage),
FlatButton(
onPressed: () {
_getCurrentLocation();
},
color: Colors.green,
child: Text("Find Location")
)
]),
)
)
);
}
}
【问题讨论】:
标签: android flutter dart location