2013-04-09 83 views
0

我使用Polaris库进行Android地图,因为它具有群集支持: Polaris with Clustering. 我不依赖谷歌地图V2因为它会离开我的目标很多设备。如何使用Polaris库自定义显示在Android地图中的信息

我需要做的是能够个性化气球中显示的信息。 当用户点击标记时,应该在左边显示一个气球,中间有4行文字,右边是另一个可绘制的文字。

我已经与Polaris创建者交换了几封邮件,他无法完全支持每个使用其库的开发人员,原因很明显。他暗示我使用MapCalloutView#setCustomView,但我无法弄清楚。

预先感谢您。

+0

''它会离开我的目标很多设备''。截至5月份不到2%,预计在年底时不到0.1%。 [Dashboards](http://developer.android.com/about/dashboards/index.html#) – 2013-05-05 10:06:54

+0

我的应用程序针对拉丁美洲,因此这些数字不够准确。 – Ejmedina 2013-05-06 13:08:48

回答

0

我终于做到了。

所有我已经扩展注释首先要增加额外的字段:

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注解,所以我可以使用额外的字段,充气布局成一个视图对象和的setText我所有的TextViews:

@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); 
     } 

这就是全部。 希望它有助于某人。

相关问题