奇怪的是,我在这里的其他任何地方都没有看到正确的答案。这可能是不可能的,但我仍在尝试。
在适用于 Android 的最新 Google Maps API 版本中,我想创建一个自定义 View ,一旦您单击它,它就会放置在标记上:
当然,我希望能够与其内部组件(即 ListView )进行交互。 即使您在 map 上四处移动,菜单仍会显示并保持附加到标记上。 据我所见,您只能在 map 上渲染位图。真的没有解决方法吗?
提前致谢
最佳答案
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.
关于java - Android:在 Google Maps API 中创建自定义 View 作为标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42233560/