【问题标题】:Flutter Map , Emulator is not displaying current location, it is displaying GooglePlex locationFlutter Map ,模拟器不显示当前位置,它显示的是 GooglePlex 位置
【发布时间】: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


    【解决方案1】:

    您的代码对我来说很好用。指向地图中的某个位置后,您是否单击了设置位置按钮?

    【讨论】:

    • 哦,好吧,在显示我的位置之前,我必须先从地图单点路线设置我的当前位置吗?
    • 感谢您的回复
    • 我在尝试在物理设备上构建和测试时遇到此错误。注意:C:\Users\Banky\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\geolocator-6.1.12\android\src\main\java\com\baseflow\geolocator\GeolocatorPlugin.java 使用或覆盖已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息。
    【解决方案2】:

    将强制 Android 位置管理器设置为 true。像这样 "position = await Geolocator.getCurrentPosition( 期望精度:LocationAccuracy.low, forceAndroidLocationManager: true);" 然后你会得到模拟器上的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      • 2012-12-25
      相关资源
      最近更新 更多