首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OSMbonusPack气泡标题未出现

OSMbonusPack气泡标题未出现
EN

Stack Overflow用户
提问于 2015-07-27 21:01:35
回答 1查看 488关注 0票数 0

上下文

我正在为Android编写一个应用程序,我使用OSMBonusPack轻松地显示标记。

我显示一个标记来显示用户的位置,使用电话GPS获取,并添加一个FolderOverlay来对其他标记进行分组(这些标记指示来自Wikipedia的POI,使用自定义API检索)。

我在我的projet中包含了bonuspack_bubble.xml布局文件,因为我想修改它以适当地缩放“更多信息”按钮。

问题

问题是POI标记被正确地添加到地图上(它们显示图标,当点击时,Info气泡显示,填充了标题和描述),但是第一个表示用户位置的标记会显示一个空信息气泡。

我试图删除FolderOverlay,我试图将starterMarker添加到与POI相同的覆盖层,我试图只显示starterMarker.毫无办法。

我做错了什么?如果您需要澄清某些点或代码,请随时询问!

谢谢!

注意:使用osmbonuspack v5.3 (AAR)、osmdroid4.3、Android 1.2.2,并在Galaxy上使用Android4.2.2进行测试。

代码:

主片段中的功能

代码语言:javascript
复制
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();

}

CustomInfoWindow.java

代码语言:javascript
复制
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();
    }
}

POI.java

代码语言:javascript
复制
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(...) { }
}

_bonuspack_bubble.xml_

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

发布于 2015-07-29 11:28:39

真正令人惊讶的是,你的应用程序没有崩溃:

您可以将CustomInfoWindow设置为startMarker,而不设置任何相关的POI对象。但是在CustomInfoWindow.onOpen中,您获得了相关的对象,并在不测试它是否为null的情况下使用它--如果它真的是POI的话。这不管用。

要么定义一个"StartInfoWindow“类,要么确保CustomInfoWindow完全支持您的startMarker。

提示:在所有POI标记之间共享同一个CustomInfoWindow对象。它更快,对记忆也更好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31663242

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档