如何更改位置或删除谷歌地图的默认GPS图标?

时间:2018-01-09 10:26:50

标签: android google-maps android-layout google-api fusedlocationproviderapi

我是谷歌地图及其apis的新手。这里我已经加载了谷歌地图并试图改变附加图像中GPS图标的位置,但它没有从其位置移动。

我使用 SupportMapFragment 加载地图,并使用 getMapAsync 方法在 onMapReady()方法中获取地图对象。我知道是否删除getMapAsync该图标将被删除但没有它我无法获得map的对象。所以这是我面临的问题。

是否有移动它的位置或移除它。 帮助将不胜感激。谢谢。

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以通过从Fragment

获取当前位置按钮的视图来更改此设置
//Fragment code to change the position of the current location button
private SupportMapFragment mapFragment;
 mapFragment = (SupportMapFragment) this.getChildFragmentManager()
                .findFragmentById(R.id.map);

 @Override
    public void onMapReady(GoogleMap googleMap) {
        try {
            map = googleMap;

            if (mapFragment != null &&
                    mapFragment.getView().findViewById(Integer.parseInt("1")) != null) {
                // Get the button view
                View locationButton = ((View) mapFragment.getView().findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
                // and next place it, on bottom right (as Google Maps app)
                RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
                        locationButton.getLayoutParams();
                // position on right bottom
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START, 0);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END, RelativeLayout.TRUE);
                layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, 0);
                int marginBottom = mNavigationListFragment.llTypeContainer.getHeight() + 5;
                int marginRight = (int)convertFromDpToPixel(context, 10);
                layoutParams.setMargins(0, 0, marginRight, marginBottom);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }


public static final float convertFromDpToPixel(Context context, float dp) {
        float ht_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
        return ht_px;
    }

隐藏该按钮使用以下代码:

@Override
    public void onMapReady(GoogleMap googleMap) {
        map = googleMap;
        map.getUiSettings().setMyLocationButtonEnabled(false);
    }

答案 1 :(得分:0)

删除onMapReady中的map = googleMap; map.getUiSettings().setMyLocationButtonEnabled(false); 添加

STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS: [STATIC_DIR, ]
STATIC_URL = '/static/'
相关问题