2013-04-09 3 views
0

사용하여 안드로이드지도에 표시되는 정보를 사용자 지정하는 방법 : 나는 많은 내 대상에서 떠날 원인 구글지도의 V2에 의존하고 있지 않다 Polaris with Clustering. 을 장치.는 클러스터링 지원이 있기 때문에 나는 안드로이드지도에 대한 폴라리스 라이브러리를 사용하고 있습니다 폴라리스 도서관

내가해야 할 일은 풍선에 표시된 정보를 개인화 할 수있게하는 것입니다. 사용자가 마커를 두드리면 그림이 왼쪽의 그림과 같이 가운데에 4 줄의 텍스트와 오른쪽에 다른 그림으로 표시되어야합니다.

필자는 분명한 이유 때문에 자신의 라이브러리를 사용하는 모든 개발자에게 전폭적 인 지원을 제공 할 수없는 폴라리스 제작자와 몇 권의 메일을 교환했습니다. 그는 MapCalloutView # setCustomView를 사용할 때를 암시했지만 나는 그것을 알 수 없다.

미리 감사드립니다.

+0

''내 장치에서 많은 장치를 벗어날 것 " 5 월 현재 2 % 미만이고 연말에는 0.1 % 미만입니다. [Dashboards] (http://developer.android.com/about/dashboards/index.html#) –

+0

내 앱이 라틴 아메리카를 대상으로하므로 이러한 수치가 정확하지 않습니다. – Ejmedina

답변

0

나는 마침내 그것을 만들었습니다. 내가 주석을 확장 한 모든

먼저 추가 필드를 추가합니다 : 나는했습니다 내 MapActivity 클래스에서

<?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> 

:

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 레이아웃을 생성 OnAnnotationSelectionChangedListener를 구현했습니다. 청취자를 설정하는 것을 잊지 마십시오. 전부

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

을 : MapActivity # onAnnotationSelected에서

나는 내 모든 TextViews에보기 개체와의 setText로 레이아웃을 부풀려, 추가 필드를 사용할 수 있도록 주석 내 CustomAnnotation을 받았습니다 캐스팅. 누군가가 도움이되기를 바랍니다.