从坐标中获取位置,并将它们放在小部件扑动地理编码中

发布于 2025-02-04 10:34:42 字数 1388 浏览 2 评论 0原文

因此,我已经有了我的坐标,现在我只想调用我的功能将这些坐标转换为真实位置。 我正在使用地理编码软件包中的此功能。

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷清清 2025-02-11 10:34:42

必须使用地图服务以显示任何地图位置。
例如,使用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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文