【问题标题】:Custom marker blank screen on some android device某些 android 设备上的自定义标记空白屏幕
【发布时间】:2015-03-23 18:59:41
【问题描述】:

我已经使用 google android map v2 实现了自定义标记。它在某些设备上运行良好,并且在某些设备上自定义标记似乎是空白的。我的自定义标记 xml 文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

            <TextView
                android:id="@+id/markerText1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:textStyle="bold"/>

            <TextView
                android:id="@+id/markerText2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />

            <TextView
                android:id="@+id/markerText3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />
            <TextView
                android:id="@+id/markerText4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/markerImage1"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:src="@drawable/ic_action_call"
            android:contentDescription="Map Info"/>
            <TextView
                android:id="@+id/markerText5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tap Here for more."
                />
    </LinearLayout>
</LinearLayout>

我已经在 java 文件中实现了它,如下所示:

    SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.fp_map);
    map = fm.getMap();
    if(map != null){

        map.setIndoorEnabled(false);
        map.setOnCameraChangeListener(getCameraChangeListener());
        //add custom window here
        map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
            @Override
            public View getInfoWindow(Marker marker) {
                return null;
            }

            @Override
            public View getInfoContents(Marker marker) {
                View v = null;
                try {
                    if(!marker.getTitle().equalsIgnoreCase("diff")) {
                        try {
                            v = getLayoutInflater().inflate(R.layout.info_window, null);
                            TextView title = (TextView) v.findViewById(R.id.markerText1);
                            TextView midMsg = (TextView) v.findViewById(R.id.markerText2);
                            TextView BelowMsg1 = (TextView) v.findViewById(R.id.markerText3);
                            TextView BelowMsg2 = (TextView) v.findViewById(R.id.markerText4);

                            String[] data = marker.getSnippet().split("\\|\\|");
                            title.setText(marker.getTitle());
                            midMsg.setText(data[0]);
                            BelowMsg1.setText("check here:" + data[2]);
                            BelowMsg2.setText(data[1] + "check here also");
                            return v;
                        } catch (Exception e) {
                            String error = e.getMessage();
                        }
                    } else {
                        return null; //so that normal view can be generted.
                    }
                } catch (Exception e){
                    String error1 = e.getMessage();
                    return null;
                }
                return v;
            }
        });

    }

最后我添加如下标记:

BitmapDescriptor loaded_icon;
loaded_icon = BitmapDescriptorFactory.fromResource(R.drawable.smiley_f);
map.addMarker((new MarkerOptions().position(new LatLng(Double.parseDouble(data[1]), Double.parseDouble(data[2])))
                                            .title(data[0])
                                            .snippet(data[5] + "||" + data[6] + "||" + data[7])
                                            .icon(loaded_icon)))
                                            .showInfoWindow();
                         

上述添加标记代码在循环中,因此可以向用户显示不同的标记。现在我的问题是对于许多用户来说,它工作得很好,但对于某些手机(例如 HTC WILDFIRE),它给出了空白屏幕作为我在 xml 文件中提到的图像的标记。

我也遇到以下错误,不确定是否与上述问题有关。 此错误在打开地图页面之前就开始出现。

E/copybit?打开帧缓冲区时出错 errno=13(权限被拒绝)

W/Adreno200-EGLSUB? <342>

&gt;

    标签: android google-maps


    【解决方案1】:

    要使用 Google Maps API v2,它需要设备能够运行 OpenGL ES 2.0 或更高版本,正如它提到的here

    但是,一些较旧的手机(主要是 2.2 或更早版本),包括HTC Wildfire, has no GPU and does not support OpenGL ES 2.0

    所以这可能是它无法显示在您的 HTC Wildfire 上的原因。

    【讨论】:

    • 所以基本上我的自定义标记不会显示在 HTC 或没有或不支持 GPU 的同一设备上。是吗??还是有其他方法可以解决。第二个问题是如果没有其他方法,那么如何区分具有GPU或支持GPU的设备在不同的android版本上。
    • 我认为你可以打开一个 webview 来使用 web api
    • ohkey..以及如何在不同的android版本上区分具有GPU或支持GPU的设备。是 glGetString(GL_VERSION);功能是否足够或需要做更多检查?
    • 但我不明白的一件事是..最初地图在默认标记下运行良好,当我切换到新的自定义标记时..map 仍在工作,只有自定义标记的文本显示为空白,但是图像显示正确,为什么会这样?它 shd 崩溃或给出错误信息,但没有显示该行为?
    • 查看更新的问题。我用上述功能检查了 openGL,它给了我真正的回应。所以我认为它有 openGL,但问题有所不同
    猜你喜欢
    • 2016-09-12
    • 1970-01-01
    • 2021-07-15
    • 2021-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    相关资源
    最近更新 更多