从坐标中获取位置,并将它们放在小部件扑动地理编码中
因此,我已经有了我的坐标,现在我只想调用我的功能将这些坐标转换为真实位置。 我正在使用地理编码软件包中的此功能。
Future<void> getfieldlocation() async {
_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
return;
}
}
_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
_permissionGranted = await location.requestPermission();
if (_permissionGranted != PermissionStatus.granted) {
return;
}
}
_locationData = await location.getLocation();
Address address = await geoCode.reverseGeocoding(
latitude: _locationData.latitude as double,
longitude: _locationData.longitude as double);
setState(() {
fieldLatitude = _locationData.latitude;
fieldLogitude = _locationData.longitude;
addressCity = address.city;
});
}
现在假设我想将结果放入我的小部件:
widget build(buildContext上下文){ var loc = getUserLocation(widget.lat,widget.long);
return Scaffold(
appBar: AppBar(
title: const Text("Adoption Form"),
backgroundColor: Colors.blueAccent,
centerTitle: true,
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Text(loc)]
)))}
但是我得到了:无效
So I already have my coordinates and now I just want to call my function to convert those coordinates into a real location.
I am using this function from geocoding package.
Future<void> getfieldlocation() async {
_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
return;
}
}
_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
_permissionGranted = await location.requestPermission();
if (_permissionGranted != PermissionStatus.granted) {
return;
}
}
_locationData = await location.getLocation();
Address address = await geoCode.reverseGeocoding(
latitude: _locationData.latitude as double,
longitude: _locationData.longitude as double);
setState(() {
fieldLatitude = _locationData.latitude;
fieldLogitude = _locationData.longitude;
addressCity = address.city;
});
}
Now suppose I want to place that result into my widget:
Widget build(BuildContext context) {
var loc = getUserLocation(widget.lat, widget.long);
return Scaffold(
appBar: AppBar(
title: const Text("Adoption Form"),
backgroundColor: Colors.blueAccent,
centerTitle: true,
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Text(loc)]
)))}
but I am getting : null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
必须使用地图服务以显示任何地图位置。
例如,使用Google Maps API将这些坐标转换为地图上的真实位置。
有关更多信息,请在此处阅读文档: https://developers.google.com/maps/documentation/maps/documentation/地理编码
There is a must to use a map service to be able to show any map location.
For example, using google maps api to convert those coordinates to a real location on the map.
For more information read the documentation here: https://developers.google.com/maps/documentation/geocoding