Android 谷歌地图自定义信息窗口

标签 android google-maps google-maps-android-api-2

我想自己设计一个不同的信息窗口,但找不到合适的方法。

如图所示:

enter image description here

当我点击标记时,我想在底部显示一个栏。我将在那里提供有关标记的详细信息。 (它将包括名称、地址、图标)并且这些名称、地址必须是可点击的。

有哪些可能的方法(ways)来做?

最佳答案

GoogleMap.InfoWindowAdapter 如果您想在屏幕底部显示标记详细信息,将显示带有标记的自定义窗口隐藏自定义窗口并在 MapView 上显示自定义 View

主.xml

 <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.iphonealsham.speedli.activitys.MapsActivity" />

        <LinearLayout
            android:id="@+id/linearLayoutCustomView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textViewTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textViewOtherDetails"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </FrameLayout>

onMarkerClick中通过return true隐藏InfoWidow并显示customView

 @Override
    public void onMapReady(GoogleMap googleMap) {
            mGoogleMap = googleMap;
            mGoogleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                @Override
                public boolean onMarkerClick(Marker marker) {
                    Log.d("GoogleMap", " click");
//focus the market
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(marker.g‌​etPosition()));
                    if (linearLayoutCustomView.getVisibility() == View.VISIBLE)
                        linearLayoutCustomView.setVisibility(View.GONE);
                    else
                        displayCustomeInfoWindow(marker);
                    return true;
                }
            });
    }

在 View 中设置详细信息

 private void displayCustomeInfoWindow(Marker marker) {
        linearLayoutCustomView.setVisibility(View.VISIBLE);
        TextView textViewTitle = linearLayoutCustomView.findViewById(R.id.textViewTitle);
        TextView textViewOtherDetails = linearLayoutCustomView.findViewById(R.id.textViewOtherDetails);
        textViewTitle.setText(marker.getTitle());
        textViewOtherDetails.setText("LatLong :: " + marker.getPosition().latitude + "," + marker.getPosition().longitude);

    }

关于Android 谷歌地图自定义信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48124134/

相关文章:

android - 通知彩色操作按钮 Android 10

android - Google map 在 APK 构建执行期间崩溃

android - App转账和api key 问题

css - 谷歌地图(街景)嵌入一个div,全屏坏了

android - Geocoder.getFromLocationName() 在带有 Google Maps V2 的 Android 4 上抛出 "Service not available"异常

android - Cloudant 连续复制 Android

android - 如何在 Android 中找出浏览器的用户代理

android - Google maps android api 使用哪个证书?

android - 如何使用 dagger2 将 Activity 注入(inject) Adapter

android - Google Maps API 和 Facebook SDK for Android 不再工作,可能是因为调试 key