Android:在 Google 地图 API 中创建自定义视图作为标记

Android: creating a Custom view as Marker in Google Maps API

奇怪的是,我在这里的其他任何地方都没有看到正确的答案。这可能是不可能的,但我仍在尝试。

在 Android 的最新 Google 地图 API 版本中,我想创建一个自定义视图,一旦您单击它,它就会放置在标记上:

Map Preview

当然,我希望能够与其内部组件(即列表视图)进行交互。 即使您在地图上四处移动,菜单仍会显示并保持附加到标记上。 据我所见,您只能在地图上渲染位图。真的没有解决方法吗?

提前致谢

Use Info window to display custom layout on google maps.

这是来自 document 的示例代码。

public class MarkerDemoActivity extends AppCompatActivity implements
        OnInfoWindowClickListener,
        OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    public void onMapReady(GoogleMap map) {
        mMap = map;
        // Add markers to the map and do other map setup.
        ...
        // Set a listener for info window events.
        mMap.setOnInfoWindowClickListener(this);
    }

    @Override
    public void onInfoWindowClick(Marker marker) {
        Toast.makeText(this, "Info window clicked",
                Toast.LENGTH_SHORT).show();
    }
}

However, Info window is not a live View, rather the view is rendered as an image onto the map. As a result, any listeners you set on the view are disregarded and you cannot distinguish between click events on various parts of the view. You are advised not to place interactive components — such as buttons, checkboxes, or text inputs — within your custom info window.