我正在使用Google Maps Android API v2,我需要一种方法来判断“我的位置”按钮的位置。
我得到了“我的位置”按钮,如下所示:
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
final GoogleMap map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
// This gets the button
map.setMyLocationEnabled(true);
发布于 2014-08-07 21:50:03
只需使用GoogleMap.setPadding(左、上、右、下),它允许您指示可能被其他视图遮挡的地图部分。设置填充将重新定位标准贴图控件,并且相机更新将使用填充区域。
https://developers.google.com/maps/documentation/android/map#map_padding
发布于 2013-12-24 04:48:49
您可以获得“我的位置”按钮并移动它,如下所示:
public class MapFragment extends SupportMapFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View mapView = super.onCreateView(inflater, container, savedInstanceState);
// 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);
}
}
发布于 2013-01-24 05:59:57
这可能不是最好的解决方案,但您可以将自己的按钮放在地图上并自行处理。它将采取以下措施:
1)将地图放在frameLayout中,并将按钮添加到顶部。例如。
<FrameLayout
android:id="@+id/mapFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.MapFragment"
map:mapType="normal"
map:uiCompass="true" />
<ImageButton
android:id="@+id/myMapLocationButton"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="bottom|right"
android:background="@drawable/myMapLocationDrawable"
android:contentDescription="My Location" />
</FrameLayout>
2)编辑地图UI设置,使按钮在调用setMyLocationEnabled(true)时不会出现。您可以通过map.getUiSettings()完成此操作。setMyLocationButtonEnabled(假);
3)处理新按钮的单击,以模拟所提供的按钮的功能。例如,调用mMap.setMyLocationEnabled(...);并将地图平移到当前位置。
希望这对你有所帮助,或者希望有人能为你提供一个更简单的解决方案;-)
https://stackoverflow.com/questions/14489880
复制相似问题