【发布时间】:2014-09-09 16:34:29
【问题描述】:
我想在 android google maps v2 中配置当前位置按钮,但我不知道该怎么做。如果您能告诉我如何在地图片段上配置自定义叠加按钮,那也会很有帮助。我只是想让这个按钮指向我将使用地理坐标而不是指向当前位置提供的自定义位置
【问题讨论】:
标签: android google-maps google-maps-api-2
我想在 android google maps v2 中配置当前位置按钮,但我不知道该怎么做。如果您能告诉我如何在地图片段上配置自定义叠加按钮,那也会很有帮助。我只是想让这个按钮指向我将使用地理坐标而不是指向当前位置提供的自定义位置
【问题讨论】:
标签: android google-maps google-maps-api-2
这是地图上的按钮覆盖图,几乎与谷歌地图按钮匹配。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
<Button
android:id="@+id/btnGPS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/mapbutton"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:text="@string/btnGPS"
android:textColor="@color/black"
android:visibility="gone" />
</RelativeLayout>
可绘制的mapbutton.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="2dp" />
<stroke
android:width="1dp"
android:color="#CC444444" />
<solid android:color="#88FFFFFF" />
</shape>
然后像任何其他按钮一样连接 onClick() 事件。 然后在按钮的 onClick() 中移动地图。 //lat,lon 是将地图移动到的位置。
mMap.moveCamera(CameraUpdateFactory
.newLatLng(lat,lon));
【讨论】: