SOS video
SOS video

Reputation: 476

Show coordinates by tapping on the map

I want an app that shows me the coordinates when I press my map. So I integrated Google Maps into my app and tried to show the coordinates with the code below. print(cordinate); works, but when I want to print the coordinates on the screen it doesn´t work.

That's the code:

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()),

Has someone an idea wht the mistake is?

Upvotes: 1

Views: 415

Answers (1)

Payam Asefi
Payam Asefi

Reputation: 2757

Since coordinate is a LAtLng I think you shoud change test like this:

String test='';

And then in your onTap:

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

Upvotes: 1

Related Questions