Android谷歌地图中未启用位置按钮

时间:2014-12-23 08:11:40

标签: android google-maps

我有什么:

我有一个正在运行的谷歌地图

发生了什么:

我看不到地图上的位置按钮

我想要什么

enter image description here

代码:

我在oncreate中调用了这个函数,我有谷歌地图的实例

private void initilizeMap() {
        try {
            if (googleMap == null) {
                //Map Explicit settings//
                //Map Rotate Gesture
                googleMap.getUiSettings().setRotateGesturesEnabled(true);
                //My Location Button
                googleMap.getUiSettings().setMyLocationButtonEnabled(true);
                //Compass Functionality
                googleMap.getUiSettings().setCompassEnabled(true);
                //Zooming Functionality
                googleMap.getUiSettings().setZoomGesturesEnabled(true);
                //Zooming Buttons
                googleMap.getUiSettings().setZoomControlsEnabled(true);
                //Showing Current Location
                googleMap.setMyLocationEnabled(true);


                // check if map is created successfully or not
                if (googleMap == null) {
                    Toast.makeText(this,"Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
                }
            }
        } catch (Exception e) {


        }
    }

清单

  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

注意::我可以看到缩放控件而不是位置

1 个答案:

答案 0 :(得分:1)

您使用地图创建的GoogleMaps实例。

// map is a GoogleMap object


map.setMyLocationEnabled(true);

 // Get the button view 

View locationButton = ((View) mapView.findViewById(1).getParent()).findViewById(2);

// and next place it, for exemple, on bottom right (as Google Maps app)

RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
// position on right bottom

rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
rlp.setMargins(0, 0, 30, 30);