Java Code Examples for com.baidu.location.BDLocation#getLatitude()

The following examples show how to use com.baidu.location.BDLocation#getLatitude() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddressEditDelegate.java    From FastWaiMai with MIT License 6 votes vote down vote up
/**
 * 根据获取到的位置在地图上移动"我"的位置
 *
 * @param location
 */
private void navigateTo(BDLocation location) {
	double longitude = location.getLongitude();
	double latitude = location.getLatitude();
	String address = location.getAddrStr();
	if (isFirstLocation) {
		currentLatLng = new LatLng(latitude, longitude);
		MapStatus.Builder builder = new MapStatus.Builder();
		MapStatus mapStatus = builder.target(currentLatLng).zoom(17.0f).build();
		mBaiduMap.animateMapStatus(MapStatusUpdateFactory
				.newMapStatus(mapStatus));
		isFirstLocation = false;

		//反向地理解析(含有poi列表)
		mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption()
				.location(currentLatLng)
				.radius(radius));
	}
	MyLocationData.Builder locationBuilder = new MyLocationData.Builder();
	locationBuilder.latitude(location.getLatitude());
	locationBuilder.longitude(location.getLongitude());
	MyLocationData locationData = locationBuilder.build();
	mBaiduMap.setMyLocationData(locationData);
}
 
Example 2
Source File: LocationService.java    From Conquer with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
    L.i(location.getLocType() + "," + +location.getOperators() + "," + location.getLatitude() + ","
            + location.getLongitude() + "," + location.getAddrStr());
    // 成功定位
    if (location.getLocType() == 161 || location.getLocType() == 61) {
        lastPoint = new LocationInfo(location.getLongitude(), location.getLatitude(),
                location.getAddrStr());
    } else {// 定位失败
        lastPoint = new LocationInfo(0, 0, "定位失败");
    }
    // 停止定位
    mLocationClient.stop();
    if (listener != null) {
        listener.onLocateCompleted(lastPoint);
    }
}
 
Example 3
Source File: LocationActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation bdLocation) {
    MyLocationData data;
    Builder builder = new Builder();
    Logger.i(TAG + ":" + "addstr:" + bdLocation.getAddrStr()
            + "\n" + "latitude:" + bdLocation.getLatitude()
            + "\n" + "longitude:" + bdLocation.getLongitude()
            + "\n" + "coortype:" + bdLocation.getCoorType());
    if (baiduMap != null) {
        data = builder.direction(bdLocation.getDirection())
                .latitude(bdLocation.getLatitude())
                .longitude(bdLocation.getLongitude())
                .build();
        baiduMap.setMyLocationData(data);
        latitude = bdLocation.getLatitude();
        longitude = bdLocation.getLongitude();
        address = bdLocation.getAddress().address;
        mNewActionBar.getRightText().setClickable(true);
    }
    if (bundle.getInt(Constants.BundleKey.LOCATION_TYPE) == TYPE_SEND) {
        startLocationAndSetIcon();
    }

}
 
Example 4
Source File: MainActivity.java    From Mobike with Apache License 2.0 6 votes vote down vote up
/**
 * des:地图跳到指定位置
 *
 * @param location
 */
private void navigateTo(BDLocation location) {
    if (isFirstLocation) {
        LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
        MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(ll);
        baiduMap.animateMapStatus(update);
        update = MapStatusUpdateFactory.zoomTo(18f);
        baiduMap.animateMapStatus(update);
        isFirstLocation = false;
    }
    MyLocationData.Builder builder = new MyLocationData.Builder();
    builder.latitude(location.getLatitude());
    builder.longitude(location.getLongitude());
    MyLocationData data = builder.build();
    baiduMap.setMyLocationData(data);
}
 
Example 5
Source File: EaseBaiduMapActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
	if (location == null) {
		return;
	}
	Log.d("map", "On location change received:" + location);
	Log.d("map", "addr:" + location.getAddrStr());
	sendButton.setEnabled(true);
	if (progressDialog != null) {
		progressDialog.dismiss();
	}

	if (lastLocation != null) {
		if (lastLocation.getLatitude() == location.getLatitude() && lastLocation.getLongitude() == location.getLongitude()) {
			Log.d("map", "same location, skip refresh");
			// mMapView.refresh(); //need this refresh?
			return;
		}
	}
	lastLocation = location;
	mBaiduMap.clear();
	LatLng llA = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
	CoordinateConverter converter= new CoordinateConverter();
	converter.coord(llA);
	converter.from(CoordinateConverter.CoordType.COMMON);
	LatLng convertLatLng = converter.convert();
	OverlayOptions ooA = new MarkerOptions().position(convertLatLng).icon(BitmapDescriptorFactory
			.fromResource(R.drawable.ease_icon_marka))
			.zIndex(4).draggable(true);
	mBaiduMap.addOverlay(ooA);
	MapStatusUpdate u = MapStatusUpdateFactory.newLatLngZoom(convertLatLng, 17.0f);
	mBaiduMap.animateMapStatus(u);
}
 
Example 6
Source File: BaiduLocationService.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation bdLocation) {
    cancel();
    if (callback != null) {
        switch (bdLocation.getLocType()) {
            case 61:
            case 161:
                Result result = new Result(
                        (float) bdLocation.getLatitude(),
                        (float) bdLocation.getLongitude()
                );
                result.setGeocodeInformation(
                        bdLocation.getCountry(),
                        bdLocation.getProvince(),
                        bdLocation.getCity(),
                        bdLocation.getDistrict()
                );
                result.inChina = bdLocation.getLocationWhere() == BDLocation.LOCATION_WHERE_IN_CN;
                callback.onCompleted(result);
                break;

            default:
                BuglyHelper.report(
                        new LocationException(
                                bdLocation.getLocType(),
                                bdLocation.getLocTypeDescription()
                        )
                );
                callback.onCompleted(null);
                break;
        }
    }
}
 
Example 7
Source File: BaiduMapActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
	if (location == null) {
		return;
	}
	Log.d("map", "On location change received:" + location);
	Log.d("map", "addr:" + location.getAddrStr());
	sendButton.setEnabled(true);
	if (progressDialog != null) {
		progressDialog.dismiss();
	}

	if (lastLocation != null) {
		if (lastLocation.getLatitude() == location.getLatitude() && lastLocation.getLongitude() == location.getLongitude()) {
			Log.d("map", "same location, skip refresh");
			// mMapView.refresh(); //need this refresh?
			return;
		}
	}
	lastLocation = location;
	mBaiduMap.clear();
	LatLng llA = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
	CoordinateConverter converter= new CoordinateConverter();
	converter.coord(llA);
	converter.from(CoordinateConverter.CoordType.COMMON);
	LatLng convertLatLng = converter.convert();
	OverlayOptions ooA = new MarkerOptions().position(convertLatLng).icon(BitmapDescriptorFactory
			.fromResource(R.drawable.icon_marka))
			.zIndex(4).draggable(true);
	mBaiduMap.addOverlay(ooA);
	MapStatusUpdate u = MapStatusUpdateFactory.newLatLngZoom(convertLatLng, 17.0f);
	mBaiduMap.animateMapStatus(u);
}
 
Example 8
Source File: FakeWeiBoActivity.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
    public void onReceiveLocation(BDLocation bdLocation) {
        Log.e(TAG, "onReceiveLocation: " + bdLocation);
        if (mLocationClient != null && mLocationClient.isStarted()) {
            mLocationClient.stop();
        }

        district.setText(bdLocation.getAddress().district);
        latLng = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());
        movie.performClick();

//        mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(latLng));
        mGeoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(new LatLng(39.977818,116.401535)));
    }
 
Example 9
Source File: MapPickerActivity.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
    if (null != location && location.getLocType() != BDLocation.TypeServerError) {
        //

        MyLocationData data = new MyLocationData.Builder()//
                // .direction(mCurrentX)//
                .accuracy(location.getRadius())//
                .latitude(location.getLatitude())//
                .longitude(location.getLongitude())//
                .build();
        mBaiduMap.setMyLocationData(data);
        // 设置自定义图标
        MyLocationConfiguration config = new MyLocationConfiguration(
                MyLocationConfiguration.LocationMode.NORMAL, true, null);
        mBaiduMap.setMyLocationConfigeration(config);
        mAddress = location.getAddrStr();
        mName = location.getStreet();
        mCity = location.getCity();

        LatLng currentLatLng = new LatLng(location.getLatitude(), location.getLongitude());
        mLoactionLatLng = currentLatLng;
        // 是否第一次定位
        if (isFirstLoc) {
            isFirstLoc = false;
            // 实现动画跳转
            MapStatusUpdate u = MapStatusUpdateFactory
                    .newLatLng(currentLatLng);
            mBaiduMap.animateMapStatus(u);
            mGeoCoder.reverseGeoCode((new ReverseGeoCodeOption())
                    .location(currentLatLng));
            return;
        }
    }

}
 
Example 10
Source File: BaiduUtils.java    From LocationProvider with Apache License 2.0 5 votes vote down vote up
public static void prinftBDLocation(BDLocation bdLocation) {
    Log.d("@@@", "====================BDLocation Strat====================");
    String str = "BDLocation{" + "locationID='" + bdLocation.getLocationID() + '\'' +
            ", locType=" + bdLocation.getLocType() +
            ", locTime='" + bdLocation.getTime() + '\'' +
            ", latitude=" + bdLocation.getLatitude() +
            ", longitude=" + bdLocation.getLongitude() +
            ", radius=" + bdLocation.getRadius() +
            ", addrStr=" + bdLocation.getAddrStr() +
            ", country='" + bdLocation.getCountry() + '\'' +
            ", countryCode='" + bdLocation.getCountryCode() + '\'' +
            ", city='" + bdLocation.getCity() + '\'' +
            ", cityCode='" + bdLocation.getCityCode() + '\'' +
            ", district='" + bdLocation.getDistrict() + '\'' +
            ", street='" + bdLocation.getStreet() + '\'' +
            ", streetNumber='" + bdLocation.getStreetNumber() + '\'' +
            ", locationDescribe='" + bdLocation.getLocationDescribe() + '\'' +
            ", buildingID='" + bdLocation.getBuildingID() + '\'' +
            ", buildingName='" + bdLocation.getBuildingName() + '\'' +
            ", floor='" + bdLocation.getFloor() + '\'' +
            ", speed=" + bdLocation.getSpeed() + '\'' +
            ", satelliteNumber=" + bdLocation.getSatelliteNumber() + '\'' +
            ", altitude=" + bdLocation.getAltitude() + '\'' +
            ", direction=" + bdLocation.getDirection() + '\'' +
            ", operators=" + bdLocation.getOperators() + '\'' +
            "}";
    Log.d("@@@", str);
    Log.d("@@@", "====================BDLocation End====================");
}
 
Example 11
Source File: LocationUtil.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation bdLocation) {

    if (bdLocation.getLocType() == BDLocation.TypeGpsLocation) { // GPS Location
        LogUtil.d(TAG, "getLocType: TypeGpsLocation");
    } else if (bdLocation.getLocType() == BDLocation.TypeNetWorkLocation) { // network location
        LogUtil.d(TAG, "getLocType: TypeNetWorkLocation");
    } else if (bdLocation.getLocType() == BDLocation.TypeOffLineLocation) { // offline location
        LogUtil.d(TAG, "getLocType: TypeOffLineLocation");
    } else {
        LogUtil.e(TAG, "getLocType: Type Error, type=" + bdLocation.getLocType());
        return;
    }

    mLocationGCJ02 = bdLocation;
    mLocationBD09LL = convertToBD09LL(bdLocation);

    mLastLongitude = bdLocation.getLongitude();
    mLastLatitude = bdLocation.getLatitude();
    mLastLongitudeBd09ll = mLocationBD09LL.getLongitude();
    mLastLatitudeBd09ll = mLocationBD09LL.getLatitude();
    if ((mRequestLocCnt++) == SAFE_POSITION_DURATION_TIME) {
        safeLastPosition();
        mRequestLocCnt = 0;
    }
    if (mOnLocationListener != null) {
        mOnLocationListener.onLocationChange(mLocationBD09LL.getLatitude(), mLocationBD09LL.getLongitude(),
                mLocationBD09LL.getRadius(), mLocationBD09LL.getDirection());
    }
}
 
Example 12
Source File: Activity_FoodDelivery.java    From FoodOrdering with Apache License 2.0 5 votes vote down vote up
@Override
        public void onReceiveLocation(BDLocation arg0) {
            if (arg0.getLocType() == BDLocation.TypeGpsLocation
                    || arg0.getLocType() == BDLocation.TypeNetWorkLocation) {
                longitude = arg0.getLongitude();
                latitude = arg0.getLatitude();
                address = arg0.getAddrStr();
//                Util.showToast(Activity_FoodDelivery.this,longitude+"/"+latitude+" "+address);
            }

        }
 
Example 13
Source File: LocationActivity.java    From Conquer with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
	// map view 销毁后不在处理新接收的位置
	if (location == null || mMapView == null) return;

	if (lastLocation != null) {
		if (lastLocation.getLatitude() == location.getLatitude() && lastLocation.getLongitude() == location.getLongitude()) {
			BmobLog.i("获取坐标相同");// 若两次请求获取到的地理位置坐标是相同的,则不再定位
			mLocClient.stop();
			return;
		}
	}
	lastLocation = location;

	BmobLog.i("lontitude = " + location.getLongitude() + ",latitude = " + location.getLatitude() + ",地址 = "
			+ lastLocation.getAddrStr());

	MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius())
	// 此处设置开发者获取到的方向信息,顺时针0-360
			.direction(100).latitude(location.getLatitude()).longitude(location.getLongitude()).build();
	mBaiduMap.setMyLocationData(locData);
	LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
	String address = location.getAddrStr();
	if (address != null && !address.equals("")) {
		lastLocation.setAddrStr(address);
	} else {
		// 反Geo搜索
		mSearch.reverseGeoCode(new ReverseGeoCodeOption().location(ll));
	}
	// 显示在地图上
	MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
	mBaiduMap.animateMapStatus(u);
	// 设置按钮可点击
	// mHeaderLayout.getRightImageButton().setEnabled(true);
}
 
Example 14
Source File: BaiduAddress.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
public void setBD09LL() {
    BDLocation bl = new BDLocation();
    bl.setLatitude(this.latitude);
    bl.setLongitude(this.longitude);
    bl = LocationClient.getBDLocationInCoorType(bl, BDLocation.BDLOCATION_GCJ02_TO_BD09LL);
    this.latitude = bl.getLatitude();
    this.longitude = bl.getLongitude();
}
 
Example 15
Source File: NfcDeviceFragment.java    From ESeal with Apache License 2.0 4 votes vote down vote up
@Override
        public void onReceiveLocation(BDLocation location) {
            // TODO Auto-generated method stub
            if (null != location && location.getLocType() != BDLocation.TypeServerError) {
                String time = location.getTime();
                double lat = location.getLatitude();
                double lng = location.getLongitude();
                String address = location.getAddrStr() + ", " + lat + "," + lng;
//                String address = lat + "," + lng;
                switch (operationSealSwitch) {
                    case STATE_OPERATION_LOCK: //上封
                        lockTime.setText(time);
                        lockLocation.setText(address);
                        break;
                    case STATE_OPERATION_UNLOCK: //解封
                        unlockTime.setText(time);
                        unlockLocation.setText(address);
                        break;
                    case STATE_OPERATION_SETTING: //配置
                        coordinateSetting = lat + "," + lng;
                        break;
                }
            } else if (null != location && location.getLocType() == BDLocation.TypeServerError) {
                switch (operationSealSwitch) {
                    case STATE_OPERATION_LOCK: //上封
                        lockLocation.setText(getString(R.string.fail_get_current_location));
                        break;
                    case STATE_OPERATION_UNLOCK: //解封
                        unlockLocation.setText(getString(R.string.fail_get_current_location));
                        break;
                }
            } else if (null != location && location.getLocType() == BDLocation.TypeNetWorkException) {
                switch (operationSealSwitch) {
                    case STATE_OPERATION_LOCK: //上封
                        lockLocation.setText(getString(R.string.fail_get_current_location));
                        break;
                    case STATE_OPERATION_UNLOCK: //解封
                        unlockLocation.setText(getString(R.string.fail_get_current_location));
                        break;
                }
            } else if (null != location && location.getLocType() == BDLocation.TypeCriteriaException) {
                switch (operationSealSwitch) {
                    case STATE_OPERATION_LOCK: //上封
                        lockLocation.setText(getString(R.string.fail_get_current_location));
                        break;
                    case STATE_OPERATION_UNLOCK: //解封
                        unlockLocation.setText(getString(R.string.fail_get_current_location));
                        break;
                }
            }

            isLocationServiceStarting = false;
        }
 
Example 16
Source File: BaiduMapRouteFragment.java    From BmapLite with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
    // map view 销毁后不在处理新接收的位置
    if (location == null || mMapView == null) {
        return;
    }

    if (null == BApp.MY_LOCATION) {
        BApp.MY_LOCATION = new MyPoiModel(TypeMap.TYPE_BAIDU);
    }

    BApp.MY_LOCATION.setName("我的位置");
    BApp.MY_LOCATION.setLatitude(location.getLatitude());
    BApp.MY_LOCATION.setLongitude(location.getLongitude());
    BApp.MY_LOCATION.setAltitude(location.getAltitude());
    BApp.MY_LOCATION.setAccuracy(location.getRadius());

    CacheInteracter interacter = new CacheInteracter(getActivity());

    if (BApp.MY_LOCATION.getLongitude() == 0 || BApp.MY_LOCATION.getLatitude() == 0
            ||BApp.MY_LOCATION.getLongitude() == 4.9E-324 || BApp.MY_LOCATION.getLatitude() == 4.9E-324){
        BApp.MY_LOCATION.setLatitude(interacter.getLatitude());
        BApp.MY_LOCATION.setLongitude(interacter.getLongitude());

    }

    MyLocationData locData = new MyLocationData.Builder()
            .direction(mXDirection)
            .latitude(BApp.MY_LOCATION.getLatitude())
            .longitude(BApp.MY_LOCATION.getLongitude())
            .accuracy((float) BApp.MY_LOCATION.getAccuracy())
            .build();
    mBaiduMap.setMyLocationData(locData);

    if (isFirstLoc || isRequest) {

        if (location.getLatitude() == 0 || location.getLongitude() == 0
                || location.getLatitude() == 4.9E-324 || location.getLongitude() == 4.9E-324){
            onMessage("无法获取到位置信息,请连接网络后再试");
        }

        MapStatus.Builder builder = new MapStatus.Builder();
        builder.target(new LatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude())).zoom(18f);
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));

        mSearchInteracter.searchLatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude(), 1, this);

        interacter.setLatitude(BApp.MY_LOCATION.getLatitude());
        interacter.setLongitude(BApp.MY_LOCATION.getLongitude());

        isRequest = false;
        isFirstLoc = false;

    }
}
 
Example 17
Source File: BaiduMapFragment.java    From BmapLite with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
    // map view 销毁后不在处理新接收的位置
    if (location == null || mMapView == null) {
        return;
    }

    if (null == BApp.MY_LOCATION) {
        BApp.MY_LOCATION = new MyPoiModel(TypeMap.TYPE_BAIDU);
    }

    BApp.MY_LOCATION.setName("我的位置");
    BApp.MY_LOCATION.setLatitude(location.getLatitude());
    BApp.MY_LOCATION.setLongitude(location.getLongitude());
    BApp.MY_LOCATION.setAltitude(location.getAltitude());
    BApp.MY_LOCATION.setAccuracy(location.getRadius());

    CacheInteracter interacter = new CacheInteracter(getActivity());

    if (BApp.MY_LOCATION.getLongitude() == 0 || BApp.MY_LOCATION.getLatitude() == 0
            || BApp.MY_LOCATION.getLongitude() == 4.9E-324 || BApp.MY_LOCATION.getLatitude() == 4.9E-324) {
        BApp.MY_LOCATION.setLatitude(interacter.getLatitude());
        BApp.MY_LOCATION.setLongitude(interacter.getLongitude());

    }

    MyLocationData locData = new MyLocationData.Builder()
            .direction(mXDirection)
            .latitude(BApp.MY_LOCATION.getLatitude())
            .longitude(BApp.MY_LOCATION.getLongitude())
            .accuracy((float) BApp.MY_LOCATION.getAccuracy())
            .build();
    mBaiduMap.setMyLocationData(locData);

    if (isFirstLoc || isRequest) {

        if (location.getLatitude() == 0 || location.getLongitude() == 0
                || location.getLatitude() == 4.9E-324 || location.getLongitude() == 4.9E-324) {
            onMessage("无法获取到位置信息,请连接网络后再试");
        }

        MapStatus.Builder builder = new MapStatus.Builder();
        builder.target(new LatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude())).zoom(18f);
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));

        mSearchInteracter.searchLatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude(), 1, this);

        interacter.setLatitude(BApp.MY_LOCATION.getLatitude());
        interacter.setLongitude(BApp.MY_LOCATION.getLongitude());

        if (isFirstLoc) {
            ((MainActivity) getActivity()).firstLocationComplete();
            isFirstLoc = false;
        }

        isRequest = false;

    }
}
 
Example 18
Source File: MapActivity.java    From BaiduMap-TrafficAssistant with MIT License 4 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {

	MyLocationData data = new MyLocationData.Builder()//
			.direction(mCurrentX)//
			.accuracy(location.getRadius())//
			.latitude(location.getLatitude())//
			.longitude(location.getLongitude())//
			.build();

	mBaiduMap.setMyLocationData(data);

	// 设置自定义图标
	MyLocationConfiguration config = new MyLocationConfiguration(
			mLocationMode, true, mIconLocation);
	mBaiduMap.setMyLocationConfigeration(config);

	// 更新经纬度
	mLatitude = location.getLatitude();
	mLongitude = location.getLongitude();

	if (isFirstIn) {
		LatLng latlng = new LatLng(location.getLatitude(),
				location.getLongitude());
		MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latlng);
		mBaiduMap.animateMapStatus(msu);
		isFirstIn = false;

		Toast.makeText(context, location.getAddrStr(),
				Toast.LENGTH_SHORT).show();
		Log.i("TAG",
				location.getAddrStr() + "\n" + location.getAltitude()
						+ "" + "\n" + location.getCity() + "\n"
						+ location.getCityCode() + "\n"
						+ location.getCoorType() + "\n"
						+ location.getDirection() + "\n"
						+ location.getDistrict() + "\n"
						+ location.getFloor() + "\n"
						+ location.getLatitude() + "\n"
						+ location.getLongitude() + "\n"
						+ location.getNetworkLocationType() + "\n"
						+ location.getProvince() + "\n"
						+ location.getSatelliteNumber() + "\n"
						+ location.getStreet() + "\n"
						+ location.getStreetNumber() + "\n"
						+ location.getTime() + "\n");

		// 弹出对话框显示定位信息;
		Builder builder = new Builder(context);
		builder.setTitle("为您获得的定位信息:");
		builder.setMessage("当前位置:" + location.getAddrStr() + "\n"
				+ "城市编号:" + location.getCityCode() + "\n" + "定位时间:"
				+ location.getTime() + "\n" + "当前纬度:"
				+ location.getLatitude() + "\n" + "当前经度:"
				+ location.getLongitude());
		builder.setPositiveButton("确定", null);
		AlertDialog alertDialog = builder.create();
		alertDialog.show();
	}// if
}
 
Example 19
Source File: BaiduMapSelectPoiFragment.java    From BmapLite with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation location) {
    // map view 销毁后不在处理新接收的位置
    if (location == null || mMapView == null) {
        return;
    }

    if (null == BApp.MY_LOCATION) {
        BApp.MY_LOCATION = new MyPoiModel(TypeMap.TYPE_BAIDU);
    }

    BApp.MY_LOCATION.setName("我的位置");
    BApp.MY_LOCATION.setLatitude(location.getLatitude());
    BApp.MY_LOCATION.setLongitude(location.getLongitude());
    BApp.MY_LOCATION.setAltitude(location.getAltitude());
    BApp.MY_LOCATION.setAccuracy(location.getRadius());

    CacheInteracter interacter = new CacheInteracter(getActivity());

    if (BApp.MY_LOCATION.getLongitude() == 0 || BApp.MY_LOCATION.getLatitude() == 0
            ||BApp.MY_LOCATION.getLongitude() == 4.9E-324 || BApp.MY_LOCATION.getLatitude() == 4.9E-324){
        BApp.MY_LOCATION.setLatitude(interacter.getLatitude());
        BApp.MY_LOCATION.setLongitude(interacter.getLongitude());

    }

    MyLocationData locData = new MyLocationData.Builder()
            .direction(mXDirection)
            .latitude(BApp.MY_LOCATION.getLatitude())
            .longitude(BApp.MY_LOCATION.getLongitude())
            .accuracy((float) BApp.MY_LOCATION.getAccuracy())
            .build();
    mBaiduMap.setMyLocationData(locData);

    if (isFirstLoc || isRequest) {

        if (location.getLatitude() == 0 || location.getLongitude() == 0
                || location.getLatitude() == 4.9E-324 || location.getLongitude() == 4.9E-324) {
            onMessage("无法获取到位置信息,请连接网络后再试");
        }

        MapStatus.Builder builder = new MapStatus.Builder();
        builder.target(new LatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude())).zoom(18f);
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));


        interacter.setLatitude(BApp.MY_LOCATION.getLatitude());
        interacter.setLongitude(BApp.MY_LOCATION.getLongitude());

        isRequest = false;
        isFirstLoc = false;

    }

}
 
Example 20
Source File: MainActivity.java    From MoveMapLocation with Apache License 2.0 4 votes vote down vote up
/**
 * 定位监听
 *
 * @param bdLocation
 */
@Override
public void onReceiveLocation(BDLocation bdLocation) {

    //如果bdLocation为空或mapView销毁后不再处理新数据接收的位置
    if (bdLocation == null || mBaiduMap == null) {
        return;
    }

    //定位数据
    MyLocationData data = new MyLocationData.Builder()
            //定位精度bdLocation.getRadius()
            .accuracy(bdLocation.getRadius())
                    //此处设置开发者获取到的方向信息,顺时针0-360
            .direction(bdLocation.getDirection())
                    //经度
            .latitude(bdLocation.getLatitude())
                    //纬度
            .longitude(bdLocation.getLongitude())
                    //构建
            .build();

    //设置定位数据
    mBaiduMap.setMyLocationData(data);

    //是否是第一次定位
    if (isFirstLoc) {
        isFirstLoc = false;
        LatLng ll = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());
        MapStatusUpdate msu = MapStatusUpdateFactory.newLatLngZoom(ll, 18);
        mBaiduMap.animateMapStatus(msu);
    }

    //获取坐标,待会用于POI信息点与定位的距离
    locationLatLng = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());
    //获取城市,待会用于POISearch
    city = bdLocation.getCity();

    //文本输入框改变监听,必须在定位完成之后
    searchAddress.addTextChangedListener(this);

    //创建GeoCoder实例对象
    geoCoder = GeoCoder.newInstance();
    //发起反地理编码请求(经纬度->地址信息)
    ReverseGeoCodeOption reverseGeoCodeOption = new ReverseGeoCodeOption();
    //设置反地理编码位置坐标
    reverseGeoCodeOption.location(new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()));
    geoCoder.reverseGeoCode(reverseGeoCodeOption);

    //设置查询结果监听者
    geoCoder.setOnGetGeoCodeResultListener(this);
}