Я пытаюсь добавить MapOverlay карту на LongPressEvent, и после этого центрирование карты, но даже без центрирования карты, всегда отображается синий значок (здесь вывод по умолчанию) перед отображением наложения.
Есть ли способ предотвратить отображение синего штифта при добавлении MapOverlay?
ОБНОВЛЕНИЕ с большим кодом:
Координаты
private class MapGestureListener implements MapGesture.OnGestureListener{
...
@Override
public boolean onLongPressEvent(PointF pointF) {
GeoCoordinate gc =map.pixelToGeo(pointF);
if(sdkMapSettingsListener!=null)
sdkMapSettingsListener.onLongPress(gc);
return false; //i've tried returning true and then use map.setCenter and the problem persists.
}
...
then on my listener:
@Override
public void onLongPress(GeoCoordinate gc) {
if(mo!=null)
{
map.removeMapOverlay(mo);
mo=null;
}//remove old overlay if exists
View view = inflater.inflate(R.layout.custom_map_info_window, null);
RelativeLayout info_window_wrapper = view.findViewById(R.id.info_window_wrapper);
info_window_wrapper.setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.getEntityColor(GPSApplication.getInstance(),Constants.EntityTheme.colorPrimary)));
ImageView imgPlaceIcon = view.findViewById(R.id.imageView_placeIcon);
imgPlaceIcon.setColorFilter(ThemeUtils.getEntityColor(GPSApplication.getInstance(),Constants.EntityTheme.colorAccent));
ImageView ivPlaceMarker = view.findViewById(R.id.ivPlaceMarker);
ivPlaceMarker.setColorFilter(ThemeUtils.getEntityColor(GPSApplication.getInstance(),Constants.EntityTheme.colorAccent));
TextView textViewPlaceName = view.findViewById(R.id.textView_PlaceName);
final TextView textViewOpenNow = view.findViewById(R.id.textView_OpenNow);
TextView textViewDistance = view.findViewById(R.id.textView_Distance);
textViewPlaceName.setTextColor(ThemeUtils.getEntityColor(GPSApplication.getInstance(),Constants.EntityTheme.primaryTextColor));
textViewDistance.setTextColor(ThemeUtils.getEntityColor(GPSApplication.getInstance(),Constants.EntityTheme.primaryTextColor));
String sDistance = SearchManager.getInstance().requestDistanceTo(gc,mContext);
textViewPlaceName.setText(sPlace);
textViewDistance.setText(sDistance);
mo = new MapOverlay(view,gc);
mo.setAnchorPoint(new PointF(ScreenUtils.convertDPToPixels(mContext,75),ScreenUtils.convertDPToPixels(mContext,108)));
map.addMapOverlay(mo);
//map.setCenter(gc, Map.Animation.LINEAR);
}
Просмотр MapOverlay
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:id="@+id/info_window_wrapper"
android:layout_width="wrap_content"
android:layout_height="69dp"
android:orientation="vertical"
android:paddingTop="@dimen/margin_xsmall"
android:paddingEnd="@dimen/margin_xsmall"
android:paddingStart="@dimen/margin_xsmall"
android:paddingBottom="25dp"
android:background="@drawable/custom_info_window_shape"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView_PlaceName"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="12sp"
android:text=""/>
<RelativeLayout
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="@id/textView_PlaceName">
<TextView
android:id="@+id/textView_OpenNow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="false"
android:textSize="12sp"
android:text="Open" />
<ImageView
android:id="@+id/imageView_placeIcon"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/textView_Distance"
android:padding="@dimen/margin_xxsmall"
android:src="@drawable/ic_place_white_24dp" />
<TextView
android:id="@+id/textView_Distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:singleLine="false"
android:text=""
android:textSize="12sp" />
</RelativeLayout>
</RelativeLayout>
<ImageView
android:id="@+id/ivPlaceMarker"
android:layout_width="32dp"
android:layout_height="32dp"
android:scaleType="fitXY"
android:src="@drawable/ic_place_white_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.47"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/info_window_wrapper" />
</androidx.constraintlayout.widget.ConstraintLayout>
Первый экран - это то, что показывает сначала (синий значок), затем второй экран (наложение карты)
ОБНОВЛЕНИЕ видео: https://www.youtube.com/watch?v=qNuZNUWDxeQ
ОБНОВЛЕНИЕ 2 - пример действия, похожего на наш проект, где возникает эта проблема и нет добавленного маркера:
public class TheThirdActivity extends AppCompatActivity {
private final static int REQUEST_CODE_ASK_PERMISSIONS = 1;
/**
* Permissions that need to be explicitly requested from end user.
*/
private static final String[] REQUIRED_SDK_PERMISSIONS = new String[] {
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE };
private Map map = null;
private SupportMapFragment mapFragment = null;
MapOverlay mo;
Context mContext;
LayoutInflater inflater;
SDKMapSettingsListener sdkMapSettingsListener;
public interface SDKMapSettingsListener {
void onLongPress(GeoCoordinate gc);
}
public void setSdkMapSettingsListener(SDKMapSettingsListener listener) {
this.sdkMapSettingsListener = listener;
}
private SupportMapFragment getMapFragment() {
return (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapfragment);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
inflater = getLayoutInflater();
setContentView(R.layout.activity_the_third);
mapFragment = getMapFragment();
boolean success = com.here.android.mpa.common.MapSettings.setIsolatedDiskCacheRootPath(
getApplicationContext().getExternalFilesDir(null) + File.separator + ".here-maps",
"com.here.android.tutorial.MapService");
if (!success) {
Toast.makeText(getApplicationContext(), "Unable to set isolated disk cache path.", Toast.LENGTH_LONG);
} else {
mapFragment.init(new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
if (error == OnEngineInitListener.Error.NONE) {
map = mapFragment.getMap();
map.setCenter(new GeoCoordinate(41.160465,-8.647859 ), Map.Animation.NONE);
map.setZoomLevel(18);
map.setMapScheme(Map.Scheme.NORMAL_TRAFFIC_NIGHT);
mapFragment.getMapGesture().addOnGestureListener(new MapGesture.OnGestureListener() {
@Override
public boolean onLongPressEvent(PointF pointF) {
GeoCoordinate gc =map.pixelToGeo(pointF);
if(sdkMapSettingsListener!=null)
sdkMapSettingsListener.onLongPress(gc);
return true;
}
@Override
public boolean onTapEvent(PointF pointF) {
if(mo!=null)
map.removeMapOverlay(mo);
mo=null;
return false;
}
@Override
public void onPanStart() {
}
@Override
public void onPanEnd() {
}
@Override
public void onMultiFingerManipulationStart() {
}
@Override
public void onMultiFingerManipulationEnd() {
}
@Override
public boolean onMapObjectsSelected(List<ViewObject> list) {
return false;
}
@Override
public boolean onDoubleTapEvent(PointF pointF) {
return false;
}
@Override
public void onPinchLocked() {
}
@Override
public boolean onPinchZoomEvent(float v, PointF pointF) {
return false;
}
@Override
public void onRotateLocked() {
}
@Override
public boolean onRotateEvent(float v) {
return false;
}
@Override
public boolean onTiltEvent(float v) {
return false;
}
@Override
public void onLongPressRelease() {
}
@Override
public boolean onTwoFingerTapEvent(PointF pointF) {
return false;
}
}, 1, true);
sdkMapSettingsListener = new SDKMapSettingsListener() {
@Override
public void onLongPress(GeoCoordinate gc) {
if(mo!=null)
{
map.removeMapOverlay(mo);
mo=null;
}
View view = inflater.inflate(R.layout.custom_map_info_window, null);
RelativeLayout info_window_wrapper = view.findViewById(R.id.info_window_wrapper);
info_window_wrapper.setBackgroundTintList(ColorStateList.valueOf(Color.BLACK));
ImageView imgPlaceIcon = view.findViewById(R.id.imageView_placeIcon);
imgPlaceIcon.setColorFilter(Color.YELLOW);
ImageView ivPlaceMarker = view.findViewById(R.id.ivPlaceMarker);
ivPlaceMarker.setColorFilter(Color.YELLOW);
TextView textViewPlaceName = view.findViewById(R.id.textView_PlaceName);
final TextView textViewOpenNow = view.findViewById(R.id.textView_OpenNow);
TextView textViewDistance = view.findViewById(R.id.textView_Distance);
textViewPlaceName.setTextColor(Color.WHITE);
textViewDistance.setTextColor(Color.WHITE);
String sDistance = requestDistanceTo(gc,mContext);
textViewPlaceName.setText("sample place");
textViewDistance.setText(sDistance);
mo = new MapOverlay(view,gc);
mo.setAnchorPoint(new PointF(convertDPToPixels(mContext,75),convertDPToPixels(mContext,108)));
map.addMapOverlay(mo);
map.setCenter(gc, Map.Animation.LINEAR);
}
};
} else {
System.out.println("ERROR: Cannot initialize Map Fragment");
}
}
});
}
}
public int convertDPToPixels(Context context, int dip) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, displayMetrics);
}
public String requestDistanceTo(@NonNull GeoCoordinate geoCoordinate, @NonNull Context mContext)
{
String sFinal="";
double dDist=0;
if(PositioningManager.getInstance().getPosition().getCoordinate().isValid())
{
dDist= PositioningManager.getInstance().getPosition().getCoordinate().distanceTo(geoCoordinate);
}
else
{
if(PositioningManager.getInstance().getLastKnownPosition().getCoordinate().isValid())
dDist= PositioningManager.getInstance().getLastKnownPosition().getCoordinate().distanceTo(geoCoordinate);
else
return "";
}
long lDist = (long) dDist;
sFinal= formatInMetricSystem(mContext,lDist);
return sFinal;
}
private static final NumberFormat FORMATTER = NumberFormat.getInstance();
public static String formatInMetricSystem(final Context context, final long distance) {
final String value;
final String unit;
if (distance < 0) { // invalid
value = "--";
unit = "m";
} else if (distance < 1000) {
value = FORMATTER.format(distance);
unit = "m";
} else {
value = FORMATTER.format(Math.round((double) distance / 1000));
unit = "km";
}
return String.format("%1$s%2$s", value, unit);
}
}