首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >更改Google Maps API的“我的位置”按钮的位置

更改Google Maps API的“我的位置”按钮的位置
EN

Stack Overflow用户
提问于 2013-01-24 05:38:30
回答 15查看 78.1K关注 0票数 84

我正在使用Google Maps Android API v2,我需要一种方法来判断“我的位置”按钮的位置。

我得到了“我的位置”按钮,如下所示:

代码语言:javascript
复制
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
final GoogleMap map = ((SupportMapFragment) getSupportFragmentManager()
        .findFragmentById(R.id.map)).getMap();

// This gets the button
map.setMyLocationEnabled(true);
EN

回答 15

Stack Overflow用户

回答已采纳

发布于 2014-08-07 21:50:03

只需使用GoogleMap.setPadding(左、上、右、下),它允许您指示可能被其他视图遮挡的地图部分。设置填充将重新定位标准贴图控件,并且相机更新将使用填充区域。

https://developers.google.com/maps/documentation/android/map#map_padding

票数 70
EN

Stack Overflow用户

发布于 2013-12-24 04:48:49

您可以获得“我的位置”按钮并移动它,如下所示:

代码语言:javascript
复制
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);
    }
}
票数 87
EN

Stack Overflow用户

发布于 2013-01-24 05:59:57

这可能不是最好的解决方案,但您可以将自己的按钮放在地图上并自行处理。它将采取以下措施:

1)将地图放在frameLayout中,并将按钮添加到顶部。例如。

代码语言:javascript
复制
<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(...);并将地图平移到当前位置。

希望这对你有所帮助,或者希望有人能为你提供一个更简单的解决方案;-)

票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14489880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档