1

まだ答えが見つからないことに驚いていますが、Google マップの情報ウィンドウで非常に単純なことを行うのに問題があります。3 つのテキストを含むカスタム InfoWindow を作成したいと考えています。そのうちの 1 つはカスタマイズ可能な色です (テキストによって異なりますが、マーカーを配置するときに代わりに引数を渡してこの色を設定するとよいでしょう)。これは v1 では非常に簡単でしたが、v2 では完全に台無しになっているようです。

私の主な活動では、カスタム レイアウトを InfoWindowAdapter に追加する次の部分があります。

class MyInfoWindowAdapter implements InfoWindowAdapter{
    private final View myContentsView;

    MyInfoWindowAdapter(){
        myContentsView = getLayoutInflater().inflate(R.layout.popup, null);
    }

    @Override
    public View getInfoContents(Marker marker) {

        TextView textStationName = (TextView) myContentsView.findViewById(R.id.textStationName);
        textStationName.setText(marker.getTitle());

        TextView textAPI = ((TextView)myContentsView.findViewById(R.id.textAPI));
        textAPI.setText(marker.getSnippet());

        return myContentsView;
    }   

    @Override
    public View getInfoWindow(Marker marker) {
        // TODO Auto-generated method stub
        return null;
    }
}

マーカーを作成するときに、「タイトル」と「スニペット」という 2 つのテキストを渡すことができます。しかし、そこに表示したいテキストが 3 つあります。そして、私がこれまで見てきたすべての例は、2 つのテキストに限定されており、3 番目 (または 4 番目、...) の要素を取得する方法はありません。

私は v4 サポート ライブラリ (API バージョン 8 を使用) を使用していますが、残念ながら、ここに記載されているハウツーは機能しません。

4

2 に答える 2

1

マップマーカーのコンテンツをアクティビティのに保存することをお勧めしMap<Marker, InfoWindowContentます。ここにInfoWindowContentは、マーカーの情報ウィンドウに入力するフィールドを持つクラスがあります。

マップにマーカーを追加した後、put情報ウィンドウのコンテンツを含むマーカーをに追加しますMap。次に、情報ウィンドウのコンテンツアダプターで、からマーカーのコンテンツを取得しますMap

次に例を示します。

public class MyActivity extends Activity {

    private static class InfoWindowContent {
        public String text1;
        public String text2;
        public String text3;
        // ... add other fields if you need them
    }

    private Map<Marker, InfoWindowContent> markersContent = new HashMap<Marker, InfoWindowContent>();

    private void addMarker() {
        Marker marker = map.addMarker(...);
        InfoWindowContent markerContent = new InfoWindowContent();
        // ... populate content for the marker

        markersContent.put(marker, markerContent);
    }

    class MyInfoWindowAdapter implements InfoWindowAdapter {

        @Override
        public View getInfoContents(Marker marker) {
            InfoWindowContent markerContent = markersContent.get(marker);

            // ... populate info window with your content
        }
    }
}
于 2013-03-15T17:55:08.167 に答える
0

または、追加情報を として配置し、次JSONObjectのようなメソッドMarkerでアクセスすることもできますgetInfoContents

    JSONObject content = new JSONObject(marker.getSnippet());
    textView1.setText(content.getString("myFirstInfo"));
    textView2.setText(content.getString("mySecondInfo"));
于 2013-03-19T09:08:26.480 に答える