我有一个正在运行的谷歌地图
我看不到地图上的位置按钮
我在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" />
注意::我可以看到缩放控件而不是位置
答案 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);