Java Code Examples for com.baidu.mapapi.map.MapStatusUpdateFactory#newLatLng()

The following examples show how to use com.baidu.mapapi.map.MapStatusUpdateFactory#newLatLng() . 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: MapPickerActivity.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
    // 通知是适配器第position个item被选择了
    mAdapter.setNotifyTip(position);
    mAdapter.notifyDataSetChanged();
    BitmapDescriptor mSelectIco = BitmapDescriptorFactory
            .fromResource(R.drawable.picker_map_geo_icon);
    mBaiduMap.clear();
    PoiInfo info = (PoiInfo) mAdapter.getItem(position);
    LatLng la = info.location;
    // 动画跳转
    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(la);
    mBaiduMap.animateMapStatus(u);
    // 添加覆盖物
    OverlayOptions ooA = new MarkerOptions().position(la)
            .icon(mSelectIco).anchor(0.5f, 0.5f);
    mBaiduMap.addOverlay(ooA);
    mLoactionLatLng = info.location;
    mAddress = info.address;
    mName = info.name;
    mCity = info.city;

    mLatitude = info.location.latitude;
    mLongitude = info.location.longitude;
    mStreet = info.name;//地图对应位置文字描述
}
 
Example 2
Source File: MainActivity.java    From Mobike with Apache License 2.0 6 votes vote down vote up
public void onMapStatusChangeFinish(MapStatus mapStatus) {
    String _str = mapStatus.toString();
    String _regex = "target lat: (.*)\ntarget lng";
    String _regex2 = "target lng: (.*)\ntarget screen x";
    changeLatitude = Double.parseDouble(latlng(_regex, _str));
    changeLongitude = Double.parseDouble(latlng(_regex2, _str));
    LatLng changeLL = new LatLng(changeLatitude, changeLongitude);
    startNodeStr = PlanNode.withLocation(changeLL);
    Log.d(TAG, "changeLatitude-----change--------" + changeLatitude);
    Log.d(TAG, "changeLongitude-----change--------" + changeLongitude);
    if (!isNeedCurrentlocation) {
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(changeLL);
        baiduMap.setMapStatus(u);
        if (Math.hypot((changeLatitude - currentLatitude),
                (changeLongitude - currentLongitude)) > 0.00001) {
            Logger.d(Math.hypot((changeLatitude - currentLatitude),
                    (changeLongitude - currentLongitude)));
            if (routeOverlay != null)
                routeOverlay.removeFromMap();
            addOverLayout(changeLatitude, changeLongitude);
        }

    }
}
 
Example 3
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 4
Source File: MapFragment.java    From MapForTour with MIT License 6 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
    Log.d("lml", "MapFragment:覆盖物被点击");
    baiduMap.hideInfoWindow();
    if (marker != null) {
        latLngshow = marker.getPosition();
        reverseGeoCodeOption.location(latLngshow);
        geoCoder.reverseGeoCode(reverseGeoCodeOption);
        tvAddOverlayGeoCoder.setText("正在获取详细位置");
        bundle = marker.getExtraInfo();

        generalIsMale = bundle.getString("general").equals("m");
        layoutAddOverlayRadarNearbyItem.setBackgroundColor(getResources().getColor(generalIsMale ? R.color.blue : R.color.pink));
        imageViewAddOverlayItem.setImageResource(generalIsMale ? R.mipmap.map_portrait_man : R.mipmap.map_portrait_woman);
        tvAddOverlayItemUserID.setText(bundle.getString("userID"));
        tvAddOverlayItemDistance.setText("距离" + bundle.getInt("distance") + "米        ");
        tvAddOverlayItemLatlng.setText("坐标:   " + latLngshow.latitude + "  ,  " + latLngshow.longitude + "           ");
        Log.d("lml", "MapFragment显示的信息:" + bundle.getString("userID"));
        Log.d("lml", bundle.getString("general") + ";" + generalIsMale);
        baiduMap.showInfoWindow(new InfoWindow(viewOverlayItem, marker.getPosition(), -70));
        MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(marker.getPosition());
        baiduMap.animateMapStatus(update);
        return true;
    } else
        return false;
}
 
Example 5
Source File: MapPickerActivity.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public void turnBack() {
    MyLocationData location = mBaiduMap.getLocationData();

    if (location == null) {
        return;
    }
    // 实现动画跳转
    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(new LatLng(location.latitude, location.longitude));
    mBaiduMap.animateMapStatus(u);
    mBaiduMap.clear();
    // 发起反地理编码检索
    mGeoCoder.reverseGeoCode((new ReverseGeoCodeOption())
            .location(new LatLng(location.latitude, location.longitude)));

}
 
Example 6
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 7
Source File: MainActivity.java    From VirtualLocation with Apache License 2.0 5 votes vote down vote up
/**
 * setCurrentMapLatLng 设置当前坐标
 */
public static void setCurrentMapLatLng(LatLng arg0) {
    curLatlng = arg0;
    mMarker.setPosition(arg0);

    // 设置地图中心点为这是位置
    LatLng ll = new LatLng(arg0.latitude, arg0.longitude);
    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
    mBaiduMap.animateMapStatus(u);

    // 根据经纬度坐标 找到实地信息,会在接口onGetReverseGeoCodeResult中呈现结果
    mSearch.reverseGeoCode(new ReverseGeoCodeOption().location(arg0));
}
 
Example 8
Source File: LocationActivity.java    From Conquer with Apache License 2.0 5 votes vote down vote up
private void initLocClient() {
	// 开启定位图层
	mBaiduMap.setMyLocationEnabled(true);
	mBaiduMap.setMyLocationConfigeration(new MyLocationConfigeration(MyLocationConfigeration.LocationMode.NORMAL,
			true, null));
	// 定位初始化
	mLocClient = new LocationClient(this);
	mLocClient.registerLocationListener(myListener);
	LocationClientOption option = new LocationClientOption();
	option.setProdName("bmobim");// 设置产品线
	option.setOpenGps(true);// 打开gps
	option.setCoorType("bd09ll"); // 设置坐标类型
	option.setScanSpan(1000);
	option.setOpenGps(true);
	option.setIsNeedAddress(true);
	option.setIgnoreKillProcess(true);
	mLocClient.setLocOption(option);
	mLocClient.start();
	if (mLocClient != null && mLocClient.isStarted()) mLocClient.requestLocation();

	if (lastLocation != null) {
		// 显示在地图上
		LatLng ll = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
		MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
		mBaiduMap.animateMapStatus(u);
	}
}
 
Example 9
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 10
Source File: MainActivity.java    From Mobike with Apache License 2.0 4 votes vote down vote up
public void getMyLocation() {
    isNeedCurrentlocation = true;
    LatLng latLng = new LatLng(currentLatitude, currentLongitude);
    MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLng);
    baiduMap.setMapStatus(msu);
}
 
Example 11
Source File: MapActivity.java    From BaiduMap-TrafficAssistant with MIT License 4 votes vote down vote up
private void centerToMyLocation() {
	LatLng latlng = new LatLng(mLatitude, mLongitude);
	MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latlng);
	mBaiduMap.animateMapStatus(msu);

}
 
Example 12
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
}