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

Add marker aka symbols not working #108

Closed
BwesShr opened this issue Oct 19, 2019 · 12 comments
Closed

Add marker aka symbols not working #108

BwesShr opened this issue Oct 19, 2019 · 12 comments
Assignees
Labels
Milestone

Comments

@BwesShr
Copy link

BwesShr commented Oct 19, 2019

I have recently tried to implement the mapbox in flutter and I am trying to add symbols and route to the mapbox map. But no symbols are displayed in the screen.
mapController.addSymbol(
SymbolOptions(
geometry: LatLng(
latitude,
longitude,
),
iconImage: driverIcon,
),
);

@TimothySealy
Copy link
Collaborator

Hi @BwesShr, which platform are you talking about? Android or iOS. For iOS there is an open PR (#79) for Symbols.

@fauzipadlaw
Copy link

I'm working on Android, not working as well

@TimothySealy
Copy link
Collaborator

Hi @fauzipadlaw, are you adding a custom symbol or a default one? If you could provide a code snippet it would really help.

Note that custom symbols have been implemented in PR #79 which has not been merged yet.

@fauzipadlaw
Copy link

Hi @TimothySealy, I use the default.

in state:

void _onMapCreated(MapboxMapController controller) {
    this.controller = controller;
    controller.onSymbolTapped.add(_onSymbolTapped);
    this.controller.addSymbol(
          SymbolOptions(
              geometry: LatLng(
                _getLat(),
                _getLng(),
              ),
              iconImage: "airport-15"),
        );
  }
MapboxMap(
                          onMapCreated: _onMapCreated,
                          myLocationEnabled: true,
                          initialCameraPosition: CameraPosition(
                              target: LatLng(_getLat(), _getLng()), zoom: 18),
                        )

@TimothySealy
Copy link
Collaborator

Just to be sure, if you run the example application do you see a symbol on the map?

I have just tested your snippet by modifying the example app (specifically the "Place symbol" page) and it seems to work but when opening the "Place symbol" for the second time I get the following error (which has also been reported here #104):

E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): java.lang.NullPointerException: Attempt to invoke virtual method 'com.mapbox.mapboxsdk.plugins.annotation.Annotation com.mapbox.mapboxsdk.plugins.annotation.SymbolManager.create(com.mapbox.mapboxsdk.plugins.annotation.Options)' on a null object reference
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at com.mapbox.mapboxgl.SymbolBuilder.build(SymbolBuilder.java:25)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at com.mapbox.mapboxgl.MapboxMapController.onMethodCall(MapboxMapController.java:406)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:645)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.flutter.io/mapbox_maps_3(12492): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)``` 

@MATTYGILO
Copy link

Having the same issue, has this been solved yet??

@tobrun tobrun self-assigned this Oct 31, 2019
@tobrun tobrun added the android label Oct 31, 2019
@tobrun tobrun added this to the v0.0.4 milestone Oct 31, 2019
@tobrun
Copy link
Collaborator

tobrun commented Nov 2, 2019

@fauzipadlaw

I updated the place_symbol.dart with:

  void _onMapCreated(MapboxMapController controller) {
    this.controller = controller;
    controller.onSymbolTapped.add(_onSymbolTapped);
    this.controller.addSymbol(
          SymbolOptions(
              geometry: LatLng(-33.840002, 151.204478),
              iconImage: "airport-15"),
        );
  }

And I'm seeing the symbol correclty loaded and not hitting exceptions mentioned here:

ezgif com-video-to-gif (6)

Happy to take another look if a full reproducible example is provided.

@tobrun
Copy link
Collaborator

tobrun commented Nov 2, 2019

@BwesShr what is the value of driver icon? Does this icon image exist in your style?

@fauzipadlaw
Copy link

@tobrun it is working now

@mopfattn
Copy link

This issue came back with 0.0.5 and it seems to be a timing issue.

I get this error when adding a symbol in the _onMapCreated callback, but it works when launching a timer to add the symbols later:

  void onMapCreated(MapboxMapController mapboxMapController) {
    ...
    var options = SymbolOptions(...);
    Timer(Duration(seconds: 1), () => mapboxMapController.addSymbol(options));
    setState(() {});
  }

@m0nac0
Copy link
Collaborator

m0nac0 commented Jan 13, 2020

@mopfattn You should only add symbols/lines/circles after the onStyleLoadedCallback has been fired (or in that callback), I think this is not sufficiently documented though

@tobrun
Copy link
Collaborator

tobrun commented Jan 14, 2020

I think this is not sufficiently documented though

Agreed, we also need to update our internal examples for this as well

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

No branches or pull requests

7 participants