2016-07-22 1 views
0

GoogleマップのAPIを使用すると、作成するすべてのマーカーに対して、その場所に関する詳細情報が表示されるカスタムプロパティが必要になります。カスタムプロパティを追加することは可能ですか?それとも別のクラスを作る必要がありますか?Androidのカスタムマーカーのプロパティ

多分このような何か?

Marker m = mMap.addMarker(new MarkerOptions() 
      .position(new LatLng(lati, longi)) 
      .title(title) 
      .snippet(snippet) 
      .customProperty1(true)); 

新しいクラスを作成する場合、コードスニペットをいただければ幸いです。

+0

実際に入力してください。 –

答えて

0

カスタムマーカーを作成し、詳細を追加することができます。

あなたはタイトルに情報を渡すのみスニペットとカスタムマーカーでそれを使用することができます

mapView.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { 

      // Use default InfoWindow frame 
      @Override 
      public View getInfoWindow(Marker arg0) { 
       return null; 
      } 

      // Defines the contents of the InfoWindow 
      @Override 
      public View getInfoContents(Marker arg0) { 

       // Getting view from the layout file info_window_layout 
       View v = getActivity().getLayoutInflater().inflate(R.layout.layout_mapinfo, null); // my custom view 

       // Getting the position from the marker 
       // LatLng latLng = arg0.getPosition(); 

       // Getting reference to the TextView to set latitude 
       TextView tvLat = (TextView) v.findViewById(R.id.tv_lat); 

       // Getting reference to the TextView to set longitude 
       TextView tvLng = (TextView) v.findViewById(R.id.tv_lng); 

       // Setting the latitude 
       tvLat.setText(arg0.getTitle()); 

       // Setting the longitude 
       AppSession.setIconTypeface(tvLng); 
       tvLng.setText(Html.fromHtml(arg0.getSnippet())); 

       // Returning the view containing InfoWindow contents 
       return v; 

      } 
     }); 

layout_mapinfo.xmlタイトルに値を渡し、スニペット、それをinterpreteする方法する方法

<?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" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/tv_lat" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textStyle="bold" 
     android:gravity="center_horizontal" 

     /> 

    <TextView 
     android:id="@+id/tv_lng" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textStyle="bold" 
     android:layout_gravity="center" 
     android:gravity="center" 

     /> 

</LinearLayout> 

あなたのカスタムビューであなたの要件に依存しています。

これが役に立ちます。

注:このスニペットは、目的の例です。

+0

ええと、スニペットが文字列値のみを受け入れる場合、配列などで複数のプロパティをスニペットに追加するにはどうすればよいですか。あなたはそれのためのいくつかのサンプルを提供できますか? –

+0

はい、文字列にカンマ区切りの値を渡して、アダプタでarrayに分割することができます。文字列をarray @ J.Teyに変換する方法を確認する – KDeogharkar

関連する問題