百度地圖定位顯示屏幕中央

/*****
 * 定位結果回調,重寫onReceiveLocation方法,能夠直接拷貝以下代碼到本身工程中修改
 */
private BDLocationListener mListener = new BDLocationListener() {
    @Override
    public void onReceiveLocation(final BDLocation location) {

        MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius())
                // 此處設置開發者獲取到的方向信息,順時針0-360
                .direction(100).latitude(location.getLatitude()).longitude(location.getLongitude()).build();
        Map.setMyLocationData(locData);



        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                tv_addstr.setText(location.getAddrStr());
                LatLnginfo(location.getLatitude(),location.getLongitude());
            }
        });
    }

    @Override
    public void onConnectHotSpotMessage(String s, int i) {
    }

};

 

private void LatLnginfo(double Latitude,double Longitude){
        LatLng ll = new LatLng(Latitude, Longitude);
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.mipmap.icon_geo);
//構建MarkerOption,用於在地圖上添加Marker
        OverlayOptions option = new MarkerOptions()
                .position(ll)
                .icon(bitmap);
//在地圖上添加Marker,並顯示
        Map.addOverlay(option);
        MapStatus.Builder builder = new MapStatus.Builder();
        builder.target(ll).zoom(18.0f);
        Map.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
    }
相關文章
相關標籤/搜索