0

クラスタリングをサポートしているため、Android Maps 用の Polaris Library を使用しています 。Polaris with Clustering です。 私は Google マップ V2 に依存していません。これは、ターゲットの多くのデバイスから除外されるためです。

私がしなければならないことは、バルーンに表示される情報をパーソナライズできるようにすることです。ユーザーがマーカーをタップすると、バルーンが表示され、左側に画像、中央に 4 行のテキスト、右側に別のドローアブルが表示されます。

Polaris の作成者と数通のメールをやり取りしましたが、明らかな理由により、彼のライブラリを使用しているすべての開発者に完全なサポートを提供することはできません。彼は MapCalloutView#setCustomView の使用をほのめかしましたが、わかりません。

前もって感謝します。

4

1 に答える 1

0

私はついにそれを機能させました。

まず、Annotation を拡張してフィールドを追加しました。

public class CustomAnnotation extends Annotation {
private CustomObject cObject;

public CustomObject getCustomObject() {
    return cObject;
}

public void setCustomObject(CustomObject cObject) {
    this.cObject = cObject;
}

public CustomAnnotation(GeoPoint point, String title, String snippet,CustomObject cObject) {
    super(point, title, snippet);
    this.cObject = cObject;
}

CallOutView のレイアウトを作成しました。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content"
android:paddingLeft="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
      android:id="@+id/balloon_inner_layout"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:layout_gravity="center_vertical">
  <ImageView
      android:id="@+id/image"
      android:layout_width="50dip"
      android:layout_height="50dip"
      android:contentDescription="@string/descr_image"
      android:src="@drawable/stub"
      android:scaleType="centerCrop"
      android:layout_gravity="center_vertical"/>
  <LinearLayout
          android:paddingLeft="5dip"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical">
      <TextView
        android:id="@+id/price"
    android:textStyle="bold"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
      <TextView
    android:id="@+id/address"
    android:textStyle="bold"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
    <TextView
      android:id="@+id/sup"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"            
      android:visibility="gone"/>
    <TextView
               android:layout_height="wrap_content"
               android:layout_width="wrap_content"
               android:id="@+id/rooms"
               android:visibility="gone"/>      
          </LinearLayout>
   </LinearLayout>

私の MapActivity クラスでは、OnAnnotationSelectionChangedListener を実装しました。リスナーを設定することを忘れないでください。

MapActivity#onAnnotationSelected では、受信した注釈を CustomAnnotation にキャストして、追加のフィールドを使用し、レイアウトをビュー オブジェクトにインフレートし、すべての TextView に setText を設定できるようにします。

@Override
public void onAnnotationSelected(PolarisMapView mapView,
        MapCalloutView calloutView, int position, Annotation annotation) {
    CustomAnnotation ca = (CustomAnnotation) annotations.get(position);
    View view = (View)getLayoutInflater().inflate(R.layout.balloon_test, null);
            CustomObject object = ca.getCustomObject();
        TextView txView = (TextView)view.findViewById(R.id.field1);
        txView.setText(object.getField1());
        txView.setVisibility(View.VISIBLE);
    ...
            //set aditional data in your callout
            ...
                    calloutView.setDisclosureEnabled(true);
        calloutView.setClickable(true);
        calloutView.setCustomView(view);
        calloutView.show(mPolarisMapView, annotation.getPoint(), false);
        }

それで全部です。それが誰かに役立つことを願っています。

于 2013-04-11T14:33:46.817 に答える