使用Aquery将图像下载到Google Map Marker

时间:2014-04-27 16:12:16

标签: java android google-maps android-maps-v2 aquery

我正在开发Android应用程序,并且在将图像下载到我的地图时遇到问题。在我的应用程序中,我使用Google Maps v2和Aquery下载图像。我想在用户点击地图上的标记时显示相关图像。这是我试图实现该功能的代码片段。

googleMap
                .setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
                    @Override
                    public void onInfoWindowClick(Marker marker) {
                        String allText = marker.getSnippet();
                        String[] bodyTextArray = allText.split("(;;)");
                        String bodyText = "";
                        String idText = "";
                        String imagePath = "";
                        if (bodyTextArray.length == 3) {
                            idText = bodyTextArray[0];
                            bodyText = bodyTextArray[1];
                            imagePath = bodyTextArray[2];

                        }
                        final View content2 = getActivity()
                                .getLayoutInflater().inflate(
                                        R.layout.map_marker, null);

                    AQuery aquery = new AQuery(getActivity(), content2);
                    aquery.id(R.id.ivInfoWindowMain)
                            .image(Utility.webSiteAddress + imagePath,
                                    true, true, 0, 0, null,
                                    AQuery.FADE_IN_NETWORK, 1.0f)
                            .visible();

                    Problem problemPass = null;
                    Object[] problemArray = problemSet.toArray();

我还有一个自定义列表视图我可以使用类似的代码在自定义视图中显示图像,但是在地图片段中,图像不会显示。

这是标记

的xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/ivInfoWindowMain"
        android:layout_width="200dip"
        android:layout_height="200dip"
        android:layout_marginRight="5dp"
        android:contentDescription="@string/image"
        android:adjustViewBounds="true" >
    </ImageView>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/txtInfoWindowTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:ellipsize="end"
            android:singleLine="true"
            android:textColor="#ff000000"
            android:textSize="14sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/txtInfoWindowEventType"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLength="40"
            android:ellipsize="end"
            android:singleLine="true"
            android:textColor="#ff7f7f7f"
            android:textSize="14sp" />
    </LinearLayout>

</LinearLayout>

如果您需要更多信息,请告诉我。我会立即更新问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

我成功使用Google Map Marker和Aquery,第一个区别在于创建AQuery:

...
AQuery aq = new AQuery(getActivity());
...

并且似乎以前使用过图像,我使用缓存:

...
Bitmap photoMarker = aq.getCachedImage(item.crop);
...
TransactionItem offsetItem = 
                new TransactionItem(item.latitude, item.longitude, photoMarkerSmall, item.id);
mClusterManager.addItem(offsetItem);
...

如果您在LogCat中遇到任何错误,请尝试,如果没有帮助发送?