当前位置: 首页 > 知识库问答 >
问题:

OSMbonusPack气泡标题不显示

鲜于阳
2023-03-14

我显示了一个标记来显示用户的位置,这是通过电话GPS获得的,并且我添加了一个FolderOverlay来分组其他标记(这些标记表示使用自定义API检索的Wikipedia中的POI)。

我在我的项目中包含了bonuspack_bubble.xml布局文件,因为我想修改它以适当地缩放“More Info”按钮。

问题

谢谢!

注意:使用osmbonuspack V5.3(AAR)、osmdroid 4.3、Android Studio 1.2.2并在带有Android 4.2.2的Galaxy S4上进行测试

代码

public void drawMap(Location location, MapView map, LocationManager locationManager, LocationListener locationListener) {
...
    final GeoPoint startPoint = new GeoPoint(location.getLatitude(), location.getLongitude());

    // Now we add a marker using osmBonusPack
    Marker startMarker = new Marker(map);
    startMarker.setPosition(startPoint);
    startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    map.getOverlays().add(startMarker);

    // We can change some properties of the marker (don't forget to refresh the map !!)
    startMarker.setInfoWindow(new CustomInfoWindow(map));
    startMarker.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_place));
    startMarker.setTitle(getString(R.string.you_are_here));
    map.invalidate();
...

    // We create an Overlay Folder to store every POI, so that they are grouped in clusters
    // if there are too many of them
    RadiusMarkerClusterer poiMarkers = new RadiusMarkerClusterer(getActivity());
    Drawable clusterIconD = ContextCompat.getDrawable(getActivity(), R.drawable.marker_cluster);
    Bitmap clusterIcon = ((BitmapDrawable)clusterIconD).getBitmap();
    poiMarkers.setIcon(clusterIcon);
    map.getOverlays().add(poiMarkers);

    // poiList is an ArrayList of custom POIs
    for (POI poi:poiList) {
        double mLat = poi.getLatitude();
        double mLong = poi.getLongitude();
        GeoPoint poiWaypoint = new GeoPoint(mLat, mLong);
        Marker marker = new Marker(map);
        marker.setPosition(poiWaypoint);
        marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
        marker.setRelatedObject(poi);
        marker.setInfoWindow(new CustomInfoWindow(map));
        marker.setTitle(poi.getName());
        marker.setSnippet(poi.getSitelink());
        Drawable icon = ContextCompat.getDrawable(getActivity(), R.drawable.ic_place);
        marker.setIcon(icon);
        poiMarkers.add(marker);
    }

    map.invalidate();

}
public class CustomInfoWindow extends MarkerInfoWindow {
    private POI mSelectedPoi;

    public CustomInfoWindow(MapView mapView) {
        super(R.layout.bonuspack_bubble, mapView);

        Button btn = (Button) (mView.findViewById(R.id.bubble_moreinfo));

        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (mSelectedPoi.getSitelink() != null) {
                    Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mSelectedPoi.getSitelink()));
                    view.getContext().startActivity(myIntent);
                }
            }
        });
    }

    @Override
    public void onOpen(Object item){
        super.onOpen(item);
        mView.findViewById(R.id.bubble_moreinfo).setVisibility(View.VISIBLE);

        Marker marker = (Marker)item;
        mSelectedPoi = (POI)marker.getRelatedObject();
    }
}
public class POI {

    // We define every variable returned by the WikiJourney API
    private double latitude;
    private double longitude;
    private String name;
    private String sitelink;
    private String type_name;
    private int type_id;
    private int id;

    public POI(...) { }
}
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@drawable/bonuspack_bubble" >
    <ImageView android:id="@+id/bubble_image"
        android:layout_width="65dp"
        android:layout_height="65dp"
        android:visibility="gone" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingStart="5dp"
        android:paddingEnd="5dp"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:orientation="vertical" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            <TextView android:id="@+id/bubble_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#000000"
                android:maxEms="17"
                android:layout_gravity="start"
                android:layout_weight="1"
                android:text="Title" />
            <Button android:id="@+id/bubble_moreinfo"
                android:background="@drawable/btn_moreinfo"
                android:visibility="gone"
                android:layout_width="25sp"
                android:layout_height="25sp"
                android:layout_gravity="end"
                android:layout_weight="0" />
        </LinearLayout>
        <TextView android:id="@+id/bubble_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000"
            android:textSize="12sp"
            android:maxEms="17"
            android:text="Description" />
        <TextView android:id="@+id/bubble_subdescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000"
            android:textSize="10sp"
            android:maxEms="17"
            android:text="Address"
            android:visibility="gone" />
    </LinearLayout>
</LinearLayout>

共有1个答案

微生烨然
2023-03-14

真正让人惊讶的是,你的app竟然没有崩溃:

您将CustomInfoWindow设置为startMarker,而不设置任何相关的POI对象。但是在CustomInfoWindow.onOpen中,您可以获得相关对象,如果它不是空的,并且如果它真的是POI,您可以不经测试就使用它。这不行。

或者定义“StartInfowIndow”类,或者确保CustomInfoWindow完全支持StartMarker。

 类似资料:
  • 我有一些我从互联网上下载的信息(文本和小的img),我想在我点击myMarkers类时显示它在气泡中。我希望这幅画既能画出风景,又不能画出风景。 问题 当应用程序是肖像的,当我杀死应用程序并重新运行它时,一切都在工作(当我点击时,我看到带有文本和img的气泡)。当我转向景观,当我的应用程序是不可见的,但活的,地图恢复标记,但当我点击他们,他们不显示气泡。 代码 这里是我的标记实现,它实现,以便在我

  • Tei正在尝试用OSM地图取代我应用程序中的谷歌地图。我一直试图通过学习他们如何使用JitPack安装和导入项目来使用这一点。工作很好。点击标记时,会显示默认信息气泡(一些浅灰色的)。如果我想修改标记气泡的背景,我应该怎么做?我没有在代码中使用任何类型的onClick方法 任何建议都将得到高度赞赏!

  • 定义 气泡组件。 图片展示 代码演示 import Popover from 'pile/dist/components/popover' const {Tooltip} = Popover <Tooltip overlay={"说明文字"} placement='left' isShow={popleftshow} idName='newIndex' setTooltipC

  • 气泡图以气泡的形式可视化度量和维度。 气泡图是一组圆圈。维度字段的每个值表示圆圈,度量值表示这些圆圈的大小。 设置气泡的颜色以区分维度中存在的成员。以下是创建气泡图的步骤。 例如,考虑数据源(如样本超市),以及是否要查找不同出货模式的利润。然后, 第1步:拖动度量利润(Profit)并拖放到“大小(Size)”窗格中。 第2步:拖动维度Ship Mode并放入“Labels”窗格。 第3步:同时将

  • 主要内容:什么是JFreeChart 气泡图,JFreeChart 气泡图的示例什么是JFreeChart 气泡图 气泡图以三维方式表示信息。此图表是散点图(XY 图表)的变体,其中数据点由气泡替换,数据的附加维度(z 值)以气泡的大小表示。 下图显示了 JFreeChart 库中包含的气泡图的一些演示版本: JFreeChart 气泡图的示例 让我们考虑以下气泡图的示例数据。 国家 汽车 公交车 卡车 印度 40 65 70 美国 30 20 50 中国 80 50 80

  • 本章节我们将为大家介绍 Highcharts 的气泡图。 我们在前面的章节已经了解了 Highcharts 配置语法。接下来让我们来看下 Highcharts 的其他配置。 配置 chart 配置 配置 chart 的 type 为 'bubble' 。chart.type 描述了图表类型。默认值为 "line"。 chart.zoomType 属性可配置图表放大 ,通过拖动鼠标进行缩放,沿x轴或