2013-07-17 74 views
8

這是我的代碼,以新的標誌物添加到我的GoogleMap空信息窗口:當標記被點擊

MarkerOptions m = new MarkerOptions(); 
m.title(title); 
m.snippet(snippet); 
m.position(location); 
mMap.addMarker(m); 

mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { 
     @Override 
     public void onInfoWindowClick(Marker marker) { 
      Toast.makeText(DemoActivity.this, "WindowClicked: "+ marker.getTitle() + ":" + marker.getSnippet(), 
        Toast.LENGTH_SHORT).show(); 
     } 
    }); 

現在,當我titlesnippet都是英文的這一切正常。 infoWindowToast按預期工作。

然而,正如在我的情況,titlesnippet在阿拉伯語中,Toast工作正常,但信息窗口顯示空窗

在我看來,就像一個阿拉伯語相關的錯誤。有沒有辦法解決它?

回答

6

解決方法是顯示自定義信息窗口。您可以通過創建一個InfoWindowAdapter並將其與GoogleMap.setInfoWindowAdapter()一起進行設置。

要替換默認信息窗口,請使用自定義渲染替換getInfoWindow(Marker),併爲getInfoContents(Marker)返回null。要僅替換默認信息窗口框架(標註泡泡)內的信息窗口內容,請在getInfoWindow(標記)中返回null,並覆蓋getInfoContents(標記)。

更多信息:https://developers.google.com/maps/documentation/android/marker#info_windows

+0

完美地工作。謝謝! – iTurki

+0

@iturki這並沒有解決我的問題。使用阿拉伯語時,我仍然有空窗口。你究竟做了什麼來解決這個問題?> – AlAsiri

+0

@AlAsiri看到我的答案。 – iTurki

7

@jimmithy回答解決了我的問題。

這只是三個步驟實施,從this project

步驟1:創建信息窗口的佈局。下面是popup.xml代碼:

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

<ImageView 
android:id="@+id/icon" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center_vertical" 
android:padding="2dip" 
android:src="@drawable/ic_launcher" 
android:contentDescription="@string/icon"/> 

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

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

<TextView 
android:id="@+id/snippet" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:textSize="15sp"/> 
</LinearLayout> 

</LinearLayout> 

第2步:創建InfoWindowAdapter的實現。這裏是PopupAdapter類:

class PopupAdapter implements InfoWindowAdapter { 
    LayoutInflater inflater=null; 

    PopupAdapter(LayoutInflater inflater) { 
    this.inflater=inflater; 
    } 

    @Override 
    public View getInfoWindow(Marker marker) { 
    return(null); 
    } 

    @Override 
    public View getInfoContents(Marker marker) { 
    View popup=inflater.inflate(R.layout.popup, null); 

    TextView tv=(TextView)popup.findViewById(R.id.title); 

    tv.setText(marker.getTitle()); 
    tv=(TextView)popup.findViewById(R.id.snippet); 
    tv.setText(marker.getSnippet()); 

    return(popup); 
    } 
} 

第3步:在你的活動,設置你的適配器連接到的GoogleMap:

mMap.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater())); 

而你設置!

+0

錯誤膨脹類, @此行 查看popup = inflater.inflate(R.layout.popup,null); 此外, 02-06 14:40:54.950:E/AndroidRuntime(24275):引起:android.content.res。資源$ NotFoundException:資源不是Drawable(顏色或路徑):TypedValue {t = 0x1/d = 0x7f020078 a = -1 r = 0x7f020078} –

+0

Thanks,fixed,helpful question and answer .. –

3

你應該使用這個命令.title("\u200e"+"عربی").

+0

完美!簡短而甜美! – offset