Android百度地图开发(二)定位之手动定位

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012382791/article/details/53887500

接上篇 Android百度地图开发(二)定位之自动定位及标注(及定位几日内瓦或坐标4.9E-324问题)

直接上代码:

布局文件如下:

<?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="match_parent"
    android:orientation="vertical">

    <com.baidu.mapapi.map.MapView
        android:id="@+id/bmapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true" />

    <ImageButton
        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" />

</RelativeLayout>


相关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();
            }
        });

请自行整合之前代码,如有疑问,欢迎留言讨论

猜你喜欢

转载自blog.csdn.net/u012382791/article/details/53887500