直接上代码:
布局文件如下:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:id="@+id/bmapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
android:id="@+id/fire_map_ib"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:background="@null"
android:src="@drawable/ic_myloc_btn_black" />
相关class代码如下:
/**
* 点击定位并将位置移动到屏幕中间
*/
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLocationClient.requestLocation();
LatLng point = new LatLng(
MyApplication.LOC_LAT, MyApplication.LOC_LON);
MapStatusUpdate u = MapStatusUpdateFactory
.newLatLng(point);
/*u = MapStatusUpdateFactory.newLatLngZoom(point,
mBaiduMap.getMaxZoomLevel());*/
mBaiduMap.animateMapStatus(u);
mBaiduMap.setMapStatus(u);
Toast.makeText(getActivity(), "定位中……", Toast.LENGTH_SHORT).show();
}
});
请自行整合之前代码,如有疑问,欢迎留言讨论