如何在android的谷歌地图V2上添加谷歌素材图标“我的位置”?
Posted
技术标签:
【中文标题】如何在android的谷歌地图V2上添加谷歌素材图标“我的位置”?【英文标题】:How to add Google material icon "my location" on google map V2 in android? 【发布时间】:2016-04-22 08:32:42 【问题描述】:我正在尝试使用 API v2 在 android 中显示地图。
我想在地图上显示 Google 素材图标“我的位置”。但是,每当我尝试添加布局时,它都不会反映在输出中。
我可以得到没有图标的地图。我需要图标来与地图集成。
当我在片段标签之外编写 ImageButton 代码时,图标显示在预览窗格中,但不在其中。
我应该把 ImageButton 代码放在哪里?
Mylayout.xml 的代码:
<RelativeLayout
android:layout_
android:layout_
android:orientation="vertical">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_
android:layout_>
</fragment>
<ImageButton
android:layout_
android:layout_
android:id="@+id/ic_gps"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_my_location_black_18dp" />
</RelativeLayout>
链接:-https://design.google.com/icons/#ic_my_location
【问题讨论】:
您是指默认的“查找我的位置”按钮吗? 【参考方案1】:获取您的地图对象 (mMap) 并在其上调用 setMyLocationEnabled(boolean)
。
mMap.setMyLocationEnabled(true);
这将添加启动“查找我的位置”操作的默认图像按钮。
【讨论】:
以上是关于如何在android的谷歌地图V2上添加谷歌素材图标“我的位置”?的主要内容,如果未能解决你的问题,请参考以下文章