如何从Google Maps Marker获取视图?

问题描述

我想将Showcaseview添加到android地图上的标记!? 展示库将视图作为参数。 如何从Marker获取视图?

我正在尝试这段代码

new GuideView.Builder(this)
    .setTitle("Guide Title Text")
    .setContentText("Guide Description Text\n .....Guide Description Text\n .....Guide Description Text .....")
    .setGravity(Gravity.auto) //optional
    .setdismisstype(dismisstype.anywhere) //optional - default dismisstype.targetView
    .setTargetView(view)
    .setContentTextSize(12)//optional
    .setTitleTextSize(14)//optional
    .build()
    .show();

其将视图作为setTargetView中的参数,而不是Marker Object

这是我要使用的图书馆 https://github.com/mreram/ShowCaseView

解决方法

Marker未查看,因此您无法从中获取View。但是无论如何,您都可以创建虚拟透明View并以编程方式将其放置在所选标记上,然后通过setTargetView方法将其传递到ShowCaseView库。因此,您需要围绕MapFragmentMapView,例如RelativeLayoutactivity_main.xml)的根视图:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mapview_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="<YOUR_PACKAGE_NAME>.MainActivity">

    <com.google.android.gms.maps.MapView android:id="@+id/mapview"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />

</RelativeLayout>

和虚拟透明视图布局(transparent_layout.xml):

<?xml version="1.0" encoding="utf-8"?>
<View
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="20dp"  <- adjust size programmatically or set to default size of Marker
    android:layout_height="30dp"
    android:layout_centerInParent="true"
    android:background="@android:color/transparent">
</View>

例如MainActivity,您需要获得根布局并为虚拟透明视图充气,并且在选择标记(例如单击)时,您应该获取所选Marker的当前屏幕坐标,并将虚拟透明视图恰好放置在其上方。对于RelativeLayout,可以通过setLeft()来获得x坐标,通过setTop()来获得y坐标(当然,您需要根据{{ 1}}锚)。像这样的东西:

Marker

当然,这只是想法的示例,您应该针对标记大小,锚点等来改进该代码。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...