简体   繁体   中英

Trying to add a mapbox map to my tablelayout but when called the map is not displaying

Else block called when mapbox map should be drawn, link to mapbox apihttps://docs.mapbox.com/

else{
    TableRow tr = new TableRow(getApplicationContext());
    TextView tdRow = new TextView(getApplicationContext())

Created map is meant to be added to already created table

 Mapbox.getInstance(getApplicationContext(), getString(R.string.MapSDK));
 MapboxMapOptions options = MapboxMapOptions.createFromAttributes(this, null)
                            .camera(new CameraPosition.Builder()
                            .target(new LatLng(lat, lng))
                            .zoom(12)
                            .build());
                    // create map

 MapView mapView = new MapView(this, options);

 tr.addView(mapView);

 table.addView(tr);

}

It looks like you are trying to create a map view programmatically, in which case I would recommend modelling your implementation off of this dynamically build a map view example .

It seems problematic that you don't have an onCreate method -- you might need to run mapView.onCreate(savedInstanceState) even without using getMapAsync (mapView.getMapAsync(new OnMapReadyCallback() {) .

If this doesn't help, can you say more about what is actually going wrong? Did the map not show up at all? Are there any log messages or crashes? Where is the code executing in the architecture of your application? Is there a reason for you to dynamically load the map view instead of just specifying it via the XML? I hope the answers to these questions can help reach a resolution!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM