简体   繁体   English

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

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

Strangely enough, I haven't seen a proper answer anywhere else on here. 奇怪的是,我在这里的任何其他地方都没有看到正确的答案。 It might not be possible, but I'm still taking a shot. 这可能是不可能的,但我仍在拍摄。

In the latest Google Maps API version for Android, I want to create a custom View that would be placed over the marker like so once you click on it : 在适用于Android的最新Google Maps API版本中,我想创建一个自定义视图,将其放置在标记之上,如果您点击它:

Map Preview 地图预览

在此输入图像描述

Of course, I want to be able to interact with its intern components, ie the listview. 当然,我希望能够与其实习组件(即列表视图)进行交互。 The menu would still show up and remain attached to the marker even if you move around on the map. 即使您在地图上移动,菜单仍会显示并保持与标记的连接。 From what I've seen you can only render a Bitmap on the map. 从我所见,你只能在地图上渲染一个位图。 Is there really no workaround ? 真的没有解决方法吗?

Thanks in advance 提前致谢

Use Info window to display custom layout on google maps. 使用“ 信息”窗口在Google地图上显示自定义布局。

This is the sample code from the 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. 建议您不要在自定义信息窗口中放置交互式组件(如按钮,复选框或文本输入)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM