44

私のAndroidアプリケーションにはグーグルマップv2があり、いくつかのマーカーがあります。ユーザーがこれらのマーカーの1つをクリックすると、タイトルポップアップが表示されます。ユーザーがクリックせずにこれらのタイトルを常に表示するにはどうすればよいですか?

4

6 に答える 6

49

だけお電話Marker.showInfoWindow();ください。https://developers.google.com/maps/documentation/android/marker#info_windowsおよびhttps://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/modelを参照してください/ Marker#showInfoWindow()

于 2013-01-29T17:21:17.133 に答える
49

そんな感じ:

googleMap.addMarker(new MarkerOptions()
    .position(new LatLng(latitude, longitude))
    .title("Your position")).showInfoWindow();
于 2013-12-17T22:27:34.140 に答える
14

あなたはこれを行うことができます:

Marker marker = mMap.addMarker(new MarkerOptions().position(currentPosition).title("Your text"));
marker.showInfoWindow();
于 2015-01-17T16:27:49.343 に答える
10

マーカーの周りの地図にマーカーのタイトルを表示するために、インターネットで見つけた解決策はどれもうまくいきませんでした。そこで私は袖をまくり上げて、この問題を解決するこのライブラリを作成しました。

https://github.com/androidseb/android-google-maps-floating-marker-titles

これがどのように機能するかのプレビューです:

プレビュー

于 2018-08-12T18:18:26.773 に答える
3

私はいくつかの実装ではあまり得意ではありませんが、ここに私のコードがあります:

public BitmapDescriptor getBitmapFromView(String title) {
        View view = LayoutInflater.from(activity.getApplicationContext()).inflate(R.layout.marker_tooltip, null);
        ((TextView) view.findViewById(R.id.tooltips_title)).setText(title);

        //Get the dimensions of the view. In my case they are in a dimen file
        int width = activity.getResources().getDimensionPixelSize(R.dimen.tooltips_width);
        int height = activity.getResources().getDimensionPixelSize(R.dimen.tooltips_height);

        int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);

        view.measure(measuredWidth, measuredHeight);
        view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());

        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);

        view.draw(canvas);

        return BitmapDescriptorFactory.fromBitmap(bitmap);
    }

...
marker.setIcon(getBitmapFromView(marker.getTitle()));
...

これをマップアプリのフラグメントにいくつかのバリエーションを付けて実装しました。たとえば、カスタム情報ウィンドウとマップ上のいくつかのイベントがありますが、その実装では、すべてのマーカータイトルを同時に表示する必要がありました。それがあなたにも役立ったかどうか教えてください

「activity.getResources()。getDimensionPixelSize(R.dimen.tooltips_width)」変数のACTIVITYは、フラグメント内のプロパティです。

于 2019-01-03T01:47:20.923 に答える
1

多分私はこれに答えるのに少し遅れていますが、以下のコードは私のために働きます:

//このライブラリを追加します

implementation 'com.google.maps.android:android-maps-utils:0.5'

//次に以下の方法を使用します

public void makersMaker(GoogleMap googleMap){
    IconGenerator iconFactory = new IconGenerator(this);                            
    Marker marker1 = googleMap.addMarker(new MarkerOptions().position(newLatLng(-1.3177336,36.8251902));                  
    marker1.setIcon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("Marker 1")));
    Marker marker2 = googleMap.addMarker(new MarkerOptions().position(new LatLng(-1.2857399,36.8214088)));                
    marker2.setIcon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("Marker 2")));
}
于 2019-01-31T12:26:56.597 に答える