0

I tried to build an application, which shows the current user location. In order to achieve this goale, I used Google-Map and location plug-in. I tried a sample I found in the internet, but I get an error and don't know why... I think I did it the same like the guy in the video did it...

This is the ode I tried:

  void _onMapCreated(GoogleMapController controller) {
    _controller = controller;
    _location.onLocationChanged().listen((l) {
      _controller.animateCamera(CameraUpdate.newCameraPosition(
          CameraPosition(target: LatLng(l.latitude, l.lomgitude), zoom: 10)));
    });
  }

 child: GoogleMap(
     markers: markers,
     initialCameraPosition: position,
     mapType: MapType.hybrid,
     onMapCreated: _onMapCreated,
     myLocationButtonEnabled: true,
  ),

This is the error I get:

Compiler message:
lib/main.dart:42:32: Error: 'onLocationChanged' isn't a function or method and can't be invoked.
    _location.onLocationChanged().listen((l) {
                               ^^^^^^^^^^^^^^^^...

Does anybody find my mistake?

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
SOS video
  • 436
  • 9
  • 21

1 Answers1

0

You can remove () of onLocationChanged()
please change from

_location.onLocationChanged().listen((l) {
  _controller.animateCamera(CameraUpdate.newCameraPosition(
      CameraPosition(target: LatLng(l.latitude, l.lomgitude), zoom: 10)));
});

to

_location.onLocationChanged.listen((l) {
  _controller.animateCamera(CameraUpdate.newCameraPosition(
      CameraPosition(target: LatLng(l.latitude, l.lomgitude), zoom: 10)));
});
chunhunghan
  • 51,087
  • 5
  • 102
  • 120