gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:28:27 28 4
gpt4 key购买 nike

我有什么:

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

发生了什么:

我在 map 上看不到位置按钮

我想要什么

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) {


}
}

list

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

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

最佳答案

您使用 map 创建的 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);

关于android - Android 谷歌地图中未启用位置按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27616433/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com