【问题标题】:I want to show info window of google map on top right corner of the google map我想在谷歌地图的右上角显示谷歌地图的信息窗口
【发布时间】:2016-03-30 23:35:22
【问题描述】:

当用户点击谷歌地图中的任何标记时,我想在地图右上角显示信息窗口。 它的信息窗口应始终显示在地图的右上角。

     // Setting a custom info window adapter for the google map
    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        // Use default InfoWindow frame if return null
        // else inflate any layout
        @Override
        public View getInfoWindow(Marker marker) {

            /*showAlertToChooseImage();*/
            if (!marker.getTitle().equalsIgnoreCase("Helipad")) {
                // Getting view from the layout file info_window_layout
                View view = getActivity().getLayoutInflater().inflate(R.layout.windowlayout, null);

                // Getting reference to the TextView to set latitude
                TextView tvGroupName = (TextView) view.findViewById(R.id.txtViewGroupName);
                tvGroupName.setText(modelItemMarker.getIncidentGropName());
                // Getting reference to the TextView to set longitude
                TextView tvAddress = (TextView) view.findViewById(R.id.txtViewAddress);
                tvAddress.setText(modelItemMarker.getLOCATION_ADDRESS());

                TextView tvDateTime = (TextView) view.findViewById(R.id.txtViewDateTime);
                tvDateTime.setText(modelItemMarker.getIncidentDateTimeField());

                // Returning the view containing InfoWindow contents
                return view;
            } else {
                return null;
            }
        }

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

    // Handle click of the infoWindow.
    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            Bundle bundle = new Bundle();
            bundle.putString(Constants.CallNO, modelItemMarker.getCadIdField());
            SideMenuFragment_Left.IsChangePwd = false;
            SideMenuFragment_Right.IsAgencies = false;
            Intent intent = new Intent(mContext, IncidentDetailActivity.class);
            intent.putExtra(Constants.INCIDENT_DETAIL, bundle);
            startActivity(intent);

        }
    });

有人可以帮忙吗。

提前致谢

【问题讨论】:

  • 在此处发布您的代码。到目前为止你做了什么以及你的实现。
  • @SagarNayak 我认为这会有所帮助。
  • 好的,您需要什么帮助?在 xml 中?
  • 点击标记信息窗口会打开。默认情况下,它会在标记上方打开。我想在地图屏幕右上角打开该信息窗口。
  • 好的,我认为标记信息数据与您同在。你可以在任何你想要的地方显示它。对吗?

标签: android google-maps


【解决方案1】:

试试这个方法。

public class MarkerDemoActivity extends AppCompatActivity implements
    OnInfoWindowClickListener,
    OnMapReadyCallback {

private GoogleMap mMap;

@Override
public void onMapReady(GoogleMap map) {
    mMap = map;
    // Add markers to the map and do other map setup.
    ...
    // Set a listener for info window events.
    mMap.setOnInfoWindowClickListener(this);
}

@Override
public void onInfoWindowClick(Marker marker) {
    Toast.makeText(this, "Info window clicked",
            Toast.LENGTH_SHORT).show();
}
}

【讨论】:

    【解决方案2】:

    作为上面的代码,您将获得标记顶部的信息窗口。但是,如果您想做左上角,我认为您需要再采用一个布局,并且您必须在单击时将此布局添加到地图活动标记。

    【讨论】:

      【解决方案3】:

      Google Maps API for Android 的当前功能无法实现这一点。尝试使用 Google Maps Javascript API 通过 WebFrame 将其实现到您的 Android 应用程序中。

      您可以使用InfoWindowOptions 通过使用pixelOffset 位置选项来自定义位置 更多关于here的信息。

      【讨论】:

        猜你喜欢
        • 2016-12-21
        • 2012-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-21
        • 1970-01-01
        • 2016-05-01
        相关资源
        最近更新 更多