首页 > 解决方案 > 点击标记 en 去不同的活动

问题描述

对于我在学校的项目,我必须制作一个应用程序,让你在学校里游览。现在我想让我的地图上的标记可点击,并让它们使用 POI 的信息进行不同的活动。我知道 onMarkerListeners 和意图,但我不知道如何实现它。

public void onMapReady(GoogleMap googleMap) {
    int height = 100;
    int width = 100;
    BitmapDrawable bitmapdraw=(BitmapDrawable)getResources().getDrawable(R.drawable.marker);
    Bitmap b=bitmapdraw.getBitmap();
    Bitmap smallMarker = Bitmap.createScaledBitmap(b, width, height, false);
    mMap = googleMap;
    mMap.setMyLocationEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(true);
    LatLng HalA = new LatLng(50.8062795, 3.2922986);
    LatLng stuvo = new LatLng(50.8061347, 3.2920485);
    LatLng bib = new LatLng(50.8062763,3.2919120);
    LatLng acco = new LatLng(50.8063492,3.2925983);

有更多的 POI,但这无关紧要。以下代码是我如何在地图上放置我的标记。

googleMap.addMarker(new MarkerOptions().position(HalA)
            .title("Hal A")
            .icon(BitmapDescriptorFactory.fromBitmap(smallMarker)));
    googleMap.addMarker(new MarkerOptions().position(stuvo)
            .title("Stuvo")
            .icon(BitmapDescriptorFactory.fromBitmap(smallMarker)));

等等。我必须将我的 onMarkerListener 放在哪里?我必须将所有内容都放在 onCreate 中吗?我必须改变什么?

标签: javaandroid-studiogoogle-maps-markers

解决方案


推荐阅读