通过点击地图显示坐标

Show coordinates by tapping on the map

我想要一个在我按下地图时显示坐标的应用程序。所以我将 Google 地图集成到我的应用程序中,并尝试使用下面的代码显示坐标。 print(cordinate); 可以,但是当我想在屏幕上打印坐标时它不起作用。

这是代码:

var test = 0;

  body: Column(
      children: <Widget>[
        Container(
          width: double.infinity,
          height: 600,
          child: GoogleMap(
            initialCameraPosition: position,
            mapType: MapType.normal,
            onMapCreated: (controller) {
              setState(() {
                _controller = controller;
              });
            },
            onTap: (cordinate) {
              _controller.animateCamera(CameraUpdate.newLatLng(cordinate));
              print(cordinate);
              test = cordinate as int;
            },
          ),
        ),
        Text(test.toString()),

有人知道错误是什么吗?

因为 coordinateLAtLng 我认为你应该像这样改变测试:

String test='';

然后在你的 onTap 中:

test = '${cordinate.latitude} - ${cordinate.longitude}';