Reputation: 715
I am developing a map app in Android using Mapbox Android SDK. I want to creat a popup on map when tap on map. Please note that not on any icon or marker. The popup should appear at the pin point of tapping position. The position information in longitude and latitude can be get from the following code.
@Override
public void onTapMap(MapView pMapView, ILatLng pPosition) {
String coords = String.format("Zoom = %f, Lat = %f, Lon = %f", pMapView.getZoomLevel(), pPosition.getLatitude(), pPosition.getLongitude());
String utfGrid = MapboxUtils.getUTFGridString(pPosition, Float.valueOf(pMapView.getZoomLevel()).intValue());
Log.i("TapForUTFGridTestFrag", String.format("coords = '%s', UTFGrid = '%s'", coords, utfGrid));
Toast.makeText(getApplicationContext(), coords + " == " + utfGrid, Toast.LENGTH_LONG).show();
}
I am actually want to get the following design. the red popup window's lower pin will be positined at the tapping position.
Upvotes: 0
Views: 2186
Reputation: 3168
using the Mapbox Android SDK 4.0.0 beta version, you can get the latlng location where the user clicked by using a listener:
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
mapboxMap.addMarker(new MarkerOptions()
.icon(/* make a marker bubble icon */)
.position(point));
}
});
}
});
What I mean by the make a bubble icon
comment is to create a bitmap drawable that looks like the icons here:
Hope this helps and feel free to ask any questions
Upvotes: 2
Reputation: 1592
I believe that you want to add a custom marker at that location which can be demonstrated via the following guide:
Drawing a marker https://www.mapbox.com/android-sdk/marker/
Hint: use the following method:
mapView.addMarker(new MarkerOptions()
.position(new LatLng(48.13863, 11.57603))
.title("Hello World!")
.snippet("Welcome to my marker."));
Since you do not wish to have a marker symbol there, I would suggest that you use the creating a custom marker guide and just pass a totally transparent marker:
https://www.mapbox.com/android-sdk/custom-marker-icon/
Upvotes: 0