Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to initialise markers on map start up #4

Open
kar1981 opened this issue Feb 16, 2021 · 0 comments
Open

how to initialise markers on map start up #4

kar1981 opened this issue Feb 16, 2021 · 0 comments

Comments

@kar1981
Copy link

kar1981 commented Feb 16, 2021

Can you please help me understand how I can add markers to the map on map first showing up?

 _kakaoMap = KakaoMap(
      onMapCreated: onMapCreated,
      initialCameraPosition: _kInitialPosition,
      compassEnabled: true,
      mapType: MapType.standard,
      hdMapTileEnabled: true,
      currentLocationTrackingMode: CurrentLocationTrackingMode.trackingModeOff,
      myLocationEnabled: true,
      markers: Set<Marker>.of(markers.values),
    );
void onMapCreated(KakaoMapController controller) async {
      final MapPoint visibleRegion = await controller.getMapCenterPoint();
      setState(() {
        _controller = controller;
        _visibleRegion = visibleRegion;
        addMarkers();
      });
   }
void addMarkers(){
//create some markers here
//add markers to the Map<MarkerId, Marker> markers
...

If I call addMarkers() inside onMapCreated, the app will throw exception:

Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'void net.daum.mf.map.api.MapView.addPOIItem(net.daum.mf.map.api.MapPOIItem)' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'void net.daum.mf.map.api.MapView.addPOIItem(net.daum.mf.map.api.MapPOIItem)' on a null object reference

Seems like the MapView is not instantiated yet.

If I call addMarkers() from a button (ie: after map fully loads), it works and all the markers are added to the map. I thought that onMapCreated callback is fired after the map has fully loaded, but it seems like this is not working.

Where can I call addMarkers() to add markers automatically without triggering it from a button?

Thanks:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant