2013-07-17 44 views
8

Đây là mã của tôi để thêm cột mốc mới cho googlemap của tôi:Rỗng InfoWindow khi Marker được nhấp

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

Bây giờ này chỉ hoạt động tốt khi titlesnippet của tôi là bằng tiếng Anh. infoWindowToast hoạt động như mong đợi.

Tuy nhiên, như trong trường hợp của tôi, titlesnippet là bằng tiếng Ả Rập, các Toast hoạt động tốt nhưng các InfoWindow thấy cửa sổ trống.

Dường như với tôi giống như lỗi liên quan đến ngôn ngữ tiếng Ả Rập. Có cách nào để giải quyết nó không?

Trả lời

6

Cách xung quanh việc này là hiển thị cửa sổ thông tin tùy chỉnh. Bạn có thể làm điều này bằng cách tạo một InfoWindowAdapter và đặt nó với GoogleMap.setInfoWindowAdapter().

Để thay thế cửa sổ thông tin mặc định, hãy ghi đè getInfoWindow (Marker) bằng hiển thị tùy chỉnh của bạn và trả lại null cho getInfoContents (Marker). Để chỉ thay thế nội dung của cửa sổ thông tin bên trong khung cửa sổ thông tin mặc định (bong bóng chú thích), trả về null trong getInfoWindow (Marker) và ghi đè lên getInfoContents (Marker) thay thế.

More Info: https://developers.google.com/maps/documentation/android/marker#info_windows

+0

Hoạt động hoàn hảo. Cảm ơn! – iTurki

+0

@iturki Điều này không giải quyết được vấn đề của tôi. Tôi vẫn có cửa sổ trống khi sử dụng tiếng Ả Rập. Bạn đã làm gì chính xác để giải quyết vấn đề?> – AlAsiri

+0

@AlAsiri Xem câu trả lời của tôi. – iTurki

7

@jimmithy câu trả lời giải quyết câu hỏi của tôi.

này chỉ một việc thực hiện ba bước của nó từ this project là:

Bước 1: Tạo bố cục của infoWindow của bạn. Dưới đây là popup.xml mã:

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

Bước 2: Tạo thực hiện của bạn của InfoWindowAdapter. Dưới đây là PopupAdapter lớp:

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

Bước 3: Trong hoạt động của bạn, thiết lập bộ chuyển đổi của mình vào googlemap:

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

Và bạn đang thiết lập!

+0

Lỗi khi tăng cấp lớp, @ dòng này Xem cửa sổ bật lên = inflater.inflate (R.layout.popup, null); Hơn nữa, 02-06 14: 40: 54.950: E/AndroidRuntime (24275): Gây ra bởi: android.content.res.Tài nguyên $ NotFoundException: Tài nguyên không phải là một Drawable (màu hoặc đường dẫn): TypedValue {t = 0x1/d = 0x7f020078 a = -1 r = 0x7f020078} –

+0

Cảm ơn, cố định, hữu ích và câu trả lời .. –

3

bạn nên sử dụng lệnh này .title("\u200e"+"عربی").

+0

Hoàn hảo! Ngắn và ngọt!!! – offset