i am using org.osmdroid:osmdroid-android:6.1.8 and making android app include map.
after i place mapview and button in layout.xml, i can't find button.
what is problem and how can i solve this problem?
here layout.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:text="Select"
/>
<org.osmdroid.views.MapView
android:id="@+id/locationMap"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</relativelayout>
here is java code
package com.example.copsys.OSM;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.copsys.R;
import org.osmdroid.api.IMapController;
import org.osmdroid.config.Configuration;
import org.osmdroid.events.MapEventsReceiver;
import org.osmdroid.tileprovider.tilesource.XYTileSource;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.ItemizedOverlayWithFocus;
import org.osmdroid.views.overlay.MapEventsOverlay;
import org.osmdroid.views.overlay.Overlay;
import org.osmdroid.views.overlay.OverlayItem;
import java.util.ArrayList;
public class LocationMap extends AppCompatActivity {
private final String TAG = "LocationMap";
MapView map = null;
XYTileSource tileSource_4uMaps;
ArrayList<OverlayItem> items;
OverlayItem here = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
//handle permissions first, before map is created. not depicted here
//load/initialize the osmdroid configuration, this can be done
Context ctx = getApplicationContext();
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
//setting this before the layout is inflated is a good idea
//it 'should' ensure that the map has a writable location for the map cache, even without permissions
//if no tiles are displayed, you can try overriding the cache path using Configuration.getInstance().setCachePath
//see also StorageUtils
//note, the load method also sets the HTTP User Agent to your application's package name, abusing osm's tile servers will get you banned based on this string
//inflate and create the map
setContentView(R.layout.osm_layout);
map = (MapView)findViewById(R.id.map);
tileSource_4uMaps = new XYTileSource("4uMaps", 8, 15, 256, ".png", new String[] {});
// tileSource_google = new XYTileSource("Google Maps Earth Kor", 8, 19, 256, ".png", new String[] {});
map.setTileSource(tileSource_4uMaps);
map.setUseDataConnection(false); //optional, but a good way to prevent loading from the network and test your zip loading.
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
IMapController mapController = map.getController();
mapController.setZoom(15);
GeoPoint startPoint = new GeoPoint( 35.86666, 128.600);
mapController.setCenter(startPoint);
//
//your items
items = new ArrayList<overlayitem>();
here = null;
// items.add(new OverlayItem("Title", "Description", startPoint)); // Lat/Lon decimal degrees
//
// //the overlay
// ItemizedOverlayWithFocus<overlayitem> mOverlay = new ItemizedOverlayWithFocus<overlayitem>(items,
// new ItemizedIconOverlay.OnItemGestureListener<overlayitem>() {
// @Override
// public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
// //do something
//// map.setTileSource(tileSource_4uMaps);
// return true;
// }
// @Override
// public boolean onItemLongPress(final int index, final OverlayItem item) {
//// map.setTileSource(tileSource_google);
// return false;
// }
// }, getApplicationContext());
// mOverlay.setFocusItemsOnTap(true);
// map.getOverlays().add(mOverlay);
MapEventsReceiver mReceive = new MapEventsReceiver() {
@Override
public boolean singleTapConfirmedHelper(GeoPoint p) {
Toast.makeText(getBaseContext(),p.getLatitude() + " - "+p.getLongitude(),Toast.LENGTH_LONG).show();
here = new OverlayItem("Here", "select", p);
items.add(here);
//the overlay
ItemizedOverlayWithFocus<OverlayItem> mOverlay = new ItemizedOverlayWithFocus<OverlayItem>(items,
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
@Override
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
//do something
// map.setTileSource(tileSource_4uMaps);
return true;
}
@Override
public boolean onItemLongPress(final int index, final OverlayItem item) {
// map.setTileSource(tileSource_google);
return false;
}
}, getApplicationContext());
mOverlay.setFocusItemsOnTap(true);
map.getOverlays().add(mOverlay);
Intent i = new Intent();
i.putExtra("lon", p.getLongitude());
i.putExtra("lat", p.getLatitude());
setResult(RESULT_OK, i);
finish();
return false;
}
@Override
public boolean longPressHelper(GeoPoint p) {
return false;
}
};
MapEventsOverlay OverlayEvents = new MapEventsOverlay(getBaseContext(), mReceive);
map.getOverlays().add(OverlayEvents);
}
public void onResume(){
super.onResume();
//this will refresh the osmdroid configuration on resuming.
//if you make changes to the configuration, use
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
//Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
map.onResume(); //needed for compass, my location overlays, v6.0.0 and up
}
public void onPause(){
super.onPause();
//this will refresh the osmdroid configuration on resuming.
//if you make changes to the configuration, use
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
//Configuration.getInstance().save(this, prefs);
map.onPause(); //needed for compass, my location overlays, v6.0.0 and up
}
}