Search in sources :

Example 1 with MapView

use of com.baidu.mapapi.map.MapView in project SmartCampus by Vegen.

the class EaseBaiduMapActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    instance = this;
    // initialize SDK with context, should call this before setContentView
    SDKInitializer.initialize(getApplicationContext());
    setContentView(R.layout.ease_activity_baidumap);
    mMapView = (MapView) findViewById(R.id.bmapView);
    sendButton = (Button) findViewById(R.id.btn_location_send);
    Intent intent = getIntent();
    double latitude = intent.getDoubleExtra("latitude", 0);
    LocationMode mCurrentMode = LocationMode.NORMAL;
    mBaiduMap = mMapView.getMap();
    MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f);
    mBaiduMap.setMapStatus(msu);
    initMapView();
    if (latitude == 0) {
        mMapView = new MapView(this, new BaiduMapOptions());
        mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, null));
        showMapWithLocationClient();
    } else {
        double longtitude = intent.getDoubleExtra("longitude", 0);
        String address = intent.getStringExtra("address");
        LatLng p = new LatLng(latitude, longtitude);
        mMapView = new MapView(this, new BaiduMapOptions().mapStatus(new MapStatus.Builder().target(p).build()));
        showMap(latitude, longtitude, address);
    }
    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
    iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
    mBaiduReceiver = new BaiduSDKReceiver();
    registerReceiver(mBaiduReceiver, iFilter);
}
Also used : IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) MapStatusUpdate(com.baidu.mapapi.map.MapStatusUpdate) LocationMode(com.baidu.mapapi.map.MyLocationConfiguration.LocationMode) BaiduMapOptions(com.baidu.mapapi.map.BaiduMapOptions) MapView(com.baidu.mapapi.map.MapView) MapStatus(com.baidu.mapapi.map.MapStatus) MyLocationConfiguration(com.baidu.mapapi.map.MyLocationConfiguration) LatLng(com.baidu.mapapi.model.LatLng)

Example 2 with MapView

use of com.baidu.mapapi.map.MapView in project AndroidStudy by tinggengyan.

the class BaiduMapActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_baidumap);
    textView = (TextView) findViewById(R.id.textView);
    MapView mMapView = (MapView) findViewById(R.id.bmapView);
    mapUtil = new BaiduMapUtil(this, mMapView);
    locationUtil = new BaiduLocationUtil(this, new BaiduLocationUtil.LocationSuccessListener() {

        @Override
        public void onReceiveLocation(BDLocation location) {
            float accuracy = location.getRadius();
            double latitude = location.getLatitude();
            double longitude = location.getLongitude();
            float direction = location.getDirection();
            int satelliteNumber = location.getSatelliteNumber();
            float speed = location.getSpeed();
            mapUtil.setCurrentLocation(accuracy, direction, longitude, latitude, satelliteNumber, speed);
        }
    });
    findViewById(R.id.refreshLocation).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            locationUtil.requestLocation();
        }
    });
    findViewById(R.id.zoomButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mapUtil.setZoom(18);
        }
    });
    mapUtil.setOnMapStatusChangeListener(new BaiduMapUtil.OnMapStatusChangeListener() {

        @Override
        public void onMapStatusChangeFinish(final MapStatus mapStatus) {
            // TODO: 2017/1/6 根据中心点,获取数据
            // 地图操作的中心点。
            LatLng target = mapStatus.target;
            // 地图操作中心点在屏幕中的坐标
            Point targetScreen = mapStatus.targetScreen;
            // 地图缩放级别 3~21
            float zoom = mapStatus.zoom;
        }
    });
}
Also used : Point(android.graphics.Point) TextView(android.widget.TextView) MapView(com.baidu.mapapi.map.MapView) View(android.view.View) Point(android.graphics.Point) BDLocation(com.baidu.location.BDLocation) MapView(com.baidu.mapapi.map.MapView) MapStatus(com.baidu.mapapi.map.MapStatus) LatLng(com.baidu.mapapi.model.LatLng)

Example 3 with MapView

use of com.baidu.mapapi.map.MapView in project AndroidStudy by tinggengyan.

the class LocationDemo method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_location);
    requestLocButton = (Button) findViewById(R.id.button1);
    mCurrentMode = LocationMode.NORMAL;
    requestLocButton.setText("普通");
    OnClickListener btnClickListener = new OnClickListener() {

        public void onClick(View v) {
            switch(mCurrentMode) {
                case NORMAL:
                    requestLocButton.setText("跟随");
                    mCurrentMode = LocationMode.FOLLOWING;
                    mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, mCurrentMarker));
                    break;
                case COMPASS:
                    requestLocButton.setText("普通");
                    mCurrentMode = LocationMode.NORMAL;
                    mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, mCurrentMarker));
                    break;
                case FOLLOWING:
                    requestLocButton.setText("罗盘");
                    mCurrentMode = LocationMode.COMPASS;
                    mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, mCurrentMarker));
                    break;
                default:
                    break;
            }
        }
    };
    requestLocButton.setOnClickListener(btnClickListener);
    RadioGroup group = (RadioGroup) this.findViewById(R.id.radioGroup);
    radioButtonListener = new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.defaulticon) {
                // 传入null则,恢复默认图标
                mCurrentMarker = null;
                mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, null));
            }
            if (checkedId == R.id.customicon) {
                // 修改为自定义marker
                mCurrentMarker = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
                mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, mCurrentMarker, accuracyCircleFillColor, accuracyCircleStrokeColor));
            }
        }
    };
    group.setOnCheckedChangeListener(radioButtonListener);
    // 地图初始化
    mMapView = (MapView) findViewById(R.id.bmapView);
    mBaiduMap = mMapView.getMap();
    // 开启定位图层
    mBaiduMap.setMyLocationEnabled(true);
    // 定位初始化
    mLocClient = new LocationClient(this);
    mLocClient.registerLocationListener(myListener);
    LocationClientOption option = new LocationClientOption();
    // 打开gps
    option.setOpenGps(true);
    // 设置坐标类型
    option.setCoorType("bd09ll");
    option.setScanSpan(1000);
    mLocClient.setLocOption(option);
    mLocClient.start();
}
Also used : LocationClient(com.baidu.location.LocationClient) OnCheckedChangeListener(android.widget.RadioGroup.OnCheckedChangeListener) RadioGroup(android.widget.RadioGroup) OnClickListener(android.view.View.OnClickListener) MyLocationConfiguration(com.baidu.mapapi.map.MyLocationConfiguration) LocationClientOption(com.baidu.location.LocationClientOption) MapView(com.baidu.mapapi.map.MapView) View(android.view.View)

Example 4 with MapView

use of com.baidu.mapapi.map.MapView in project wechat by motianhuo.

the class BaiduMapActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    instance = this;
    // 在使用SDK各组件之前初始化context信息,传入ApplicationContext
    // 注意该方法要再setContentView方法之前实现
    SDKInitializer.initialize(getApplicationContext());
    setContentView(R.layout.activity_baidumap);
    mMapView = (MapView) findViewById(R.id.bmapView);
    txt_right = (TextView) findViewById(R.id.txt_right);
    txt_right.setText("发送");
    txt_right.setVisibility(View.VISIBLE);
    txt_title = (TextView) findViewById(R.id.txt_title);
    txt_title.setText("位置");
    img_back = (ImageView) findViewById(R.id.img_back);
    img_back.setVisibility(View.VISIBLE);
    Intent intent = getIntent();
    double latitude = intent.getDoubleExtra("latitude", 0);
    mCurrentMode = LocationMode.NORMAL;
    mBaiduMap = mMapView.getMap();
    mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
    mBaiduMap.setMyLocationEnabled(true);
    MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f);
    mBaiduMap.setMapStatus(msu);
    initMapView();
    if (latitude == 0) {
        BaiduMapOptions mapoption = new BaiduMapOptions();
        mMapView = new MapView(this, mapoption);
        mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, null));
        showMapWithLocationClient();
    } else {
        double longtitude = intent.getDoubleExtra("longitude", 0);
        String address = intent.getStringExtra("address");
        LatLng p = new LatLng(latitude, longtitude);
        mMapView = new MapView(this, new BaiduMapOptions().mapStatus(new MapStatus.Builder().target(p).build()));
        showMap(latitude, longtitude, address);
    }
    // 注册 SDK 广播监听者
    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
    iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
    mBaiduReceiver = new BaiduSDKReceiver();
    registerReceiver(mBaiduReceiver, iFilter);
    initClick();
}
Also used : MapStatusUpdate(com.baidu.mapapi.map.MapStatusUpdate) IntentFilter(android.content.IntentFilter) BaiduMapOptions(com.baidu.mapapi.map.BaiduMapOptions) MapView(com.baidu.mapapi.map.MapView) Intent(android.content.Intent) MapStatus(com.baidu.mapapi.map.MapStatus) MyLocationConfiguration(com.baidu.mapapi.map.MyLocationConfiguration) LatLng(com.baidu.mapapi.model.LatLng)

Aggregations

MapView (com.baidu.mapapi.map.MapView)4 MapStatus (com.baidu.mapapi.map.MapStatus)3 MyLocationConfiguration (com.baidu.mapapi.map.MyLocationConfiguration)3 LatLng (com.baidu.mapapi.model.LatLng)3 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 View (android.view.View)2 BaiduMapOptions (com.baidu.mapapi.map.BaiduMapOptions)2 MapStatusUpdate (com.baidu.mapapi.map.MapStatusUpdate)2 Point (android.graphics.Point)1 OnClickListener (android.view.View.OnClickListener)1 RadioGroup (android.widget.RadioGroup)1 OnCheckedChangeListener (android.widget.RadioGroup.OnCheckedChangeListener)1 TextView (android.widget.TextView)1 BDLocation (com.baidu.location.BDLocation)1 LocationClient (com.baidu.location.LocationClient)1 LocationClientOption (com.baidu.location.LocationClientOption)1 LocationMode (com.baidu.mapapi.map.MyLocationConfiguration.LocationMode)1