当前位置: 首页>>代码示例>>Java>>正文


Java DistanceUtil类代码示例

本文整理汇总了Java中com.baidu.mapapi.utils.DistanceUtil的典型用法代码示例。如果您正苦于以下问题:Java DistanceUtil类的具体用法?Java DistanceUtil怎么用?Java DistanceUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DistanceUtil类属于com.baidu.mapapi.utils包,在下文中一共展示了DistanceUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startBikingNavi

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
/**
 * 启动百度地图骑行导航(Native)
 */
private static void startBikingNavi(Activity activity, LatLng startLL, LatLng endLL) {
    //距离太近toast提示(100米内)
    double dis = DistanceUtil.getDistance(new LatLng(startLL.latitude, startLL.longitude), new LatLng(endLL.latitude, endLL.longitude));
    if (dis <= 100) {
        Toast.makeText(activity, "起点、途经点、终点距离太近", Toast.LENGTH_SHORT).show();
        return;
    }
    // 构建 导航参数
    NaviParaOption para = new NaviParaOption()
            .startPoint(startLL).endPoint(endLL);
    try {
        BaiduMapNavigation.openBaiduMapBikeNavi(para, activity);
    } catch (BaiduMapAppNotSupportNaviException e) {
        e.printStackTrace();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:NavUtil.java

示例2: startNative_Baidu

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
/**
 * 通过Uri跳转到百度地图导航
 */
public static void startNative_Baidu(Activity activity, LatLng pt1, LatLng pt2, String start_address, String end_address) {
    try {
        double dis = DistanceUtil.getDistance(new LatLng(pt1.latitude,pt1.longitude), new LatLng(pt2.latitude,pt2.longitude));
        if (dis <= 100) {
            Toast.makeText(activity, "起点、途经点、终点距离太近", Toast.LENGTH_SHORT).show();
            return;
        }
        String start_latlng = pt1.latitude + "," + pt1.longitude;
        String end_latlng = pt2.latitude + "," + pt2.longitude;
        Intent intent = Intent.getIntent("intent://map/direction?origin=latlng:"+start_latlng+"|name:"+"Start"+"&destination=latlng:"+end_latlng+"|name:"+"End"+"&mode=riding&src=这里随便写#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");
        Log.d("gaolei", "---------------" + start_address + "," + end_address);
        activity.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(activity, "地址解析错误", Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:NavUtil.java

示例3: onBindViewHolder

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
@Override
public void onBindViewHolder(NaviPointHolder holder, int position) {
    PoiInfo poiInfo = list.get(position);
    holder.mTpiNameText.setText((position + 1) + "." + poiInfo.name);
    holder.mTpiAddressText.setText(poiInfo.address);
    if (addMode) {
        holder.mTpiItemConfirmText.setText("添加");
        holder.mTpiDistanceText.setVisibility(View.GONE);
    } else {
        holder.mTpiItemConfirmText.setText("出发");
        holder.mTpiDistanceText.setVisibility(View.VISIBLE);
        double distance = DistanceUtil.getDistance(new LatLng(address.getLatitude(), address.getLongitude()),
                poiInfo.location) / 1000;
        holder.mTpiDistanceText.setText(String.format("%.1f", distance) + "km");
    }
    holder.mTpiTargetConfirmBt.setTag(position);
    holder.itemView.setTag(position);
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:19,代码来源:NaviConfirmPointActivity.java

示例4: update

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
@Override
public void update(Address addr) {
    Log.i(TAG, "onReceiveLocation>>");
    if (addr == null)
        return;
    // BDLocation location = new BDLocation();
    // location.setLatitude(addr.getLatitude());
    // location.setLongitude(addr.getLongitude());
    // location = LocationClient.getBDLocationInCoorType(location, BDLocation.BDLOCATION_GCJ02_TO_BD09LL);
    LatLng now = new LatLng(addr.getLatitude(), addr.getLongitude());
    // location.setLatitude(address.getLatitude());
    // location.setLongitude(address.getLongitude());
    // location = LocationClient.getBDLocationInCoorType(location, BDLocation.BDLOCATION_GCJ02_TO_BD09LL);
    LatLng before = new LatLng(address.getLatitude(), address.getLongitude());

    address = addr;
    // ((TextView) mContext.findViewById(R.id.ast_location_text)).setText(addr.getAddressDetail());
    if (DistanceUtil.getDistance(before, now) > 2000) {
        updateHomeAndCompany();
        if (goHomeNodes.size() > 0)
            setGoHomeCalculate();
        else
            setGoCompanyCalculate();
    }
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:26,代码来源:TrafficShowPresenter.java

示例5: getZoom

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
/**
 * 获取百度地图显示等级
 * 范围3-21级
 */
private int getZoom(double minLat, double maxLat, double minLng, double maxLng) {
    LatLng minLatLng = new LatLng(minLat, minLng);
    LatLng maxLatLng = new LatLng(maxLat, maxLng);
    double distance = DistanceUtil.getDistance(minLatLng, maxLatLng);

    if (distance <= 100.0d) {
        return 16;
    }

    for (int i = 0; i < BAIDU_MAP_ZOOM.length; i++) {
        if (BAIDU_MAP_ZOOM[i] - distance > 0) {
            moveDistance = (BAIDU_MAP_ZOOM[i] - distance) / DISTANCE_RATIO;
            Log.d(TAG, "getZoom() moveDistance = " + moveDistance);
            return 19 - i + 3;
        }
    }
    return 16;
}
 
开发者ID:agenthun,项目名称:ESeal,代码行数:23,代码来源:FreightTrackBaiduMapFragment.java

示例6: getGoogleMapZoom

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
/**
 * 获取Google地图显示等级
 * 范围0-18级
 */
private int getGoogleMapZoom(double minLat, double maxLat, double minLng, double maxLng) {
    LatLng minLatLng = new LatLng(minLat, minLng);
    LatLng maxLatLng = new LatLng(maxLat, maxLng);
    double distance = DistanceUtil.getDistance(minLatLng, maxLatLng);

    if (distance == 0.0d) {
        return 12;
    }
    if (distance > 0.0d && distance <= 100.0d) {
        return 18;
    }

    for (int i = 0; i < BAIDU_MAP_ZOOM.length; i++) {
        if (BAIDU_MAP_ZOOM[i] - distance > 0) {
            moveDistance = (BAIDU_MAP_ZOOM[i] - distance) / DISTANCE_RATIO;
            Log.d(TAG, "getZoom() moveDistance = " + moveDistance);
            return 18 - i;
        }
    }
    return 12;
}
 
开发者ID:agenthun,项目名称:ESeal,代码行数:26,代码来源:FreightTrackBaiduMapFragment.java

示例7: isBusNear

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
/**
 * 判断车辆是否快抵达此站
 * @return
 */
private LatLng isBusNear(int position){
	//TODO 判断公交车是否在此站之前,上一个站点之后
	if(position==0) return null;
	
	LatLng startPos = mBusStationList.get(position-1).getLocation();
	LatLng endPos = mBusStationList.get(position).getLocation();
	
	double cLineDis = DistanceUtil.getDistance(startPos, endPos);
	LatLng cricleCenter = new LatLng((startPos.latitude+endPos.latitude)/2,
			(startPos.longitude+endPos.longitude)/2);
	for(Bus bus : runBusList){
		double cDis = DistanceUtil.getDistance(new LatLng(bus.getLatitude(),bus.getLongitude()), endPos);
		
		if(SpatialRelationUtil.isCircleContainsPoint(cricleCenter,
				(int) DistanceUtil.getDistance(startPos, endPos)/2, 
				new LatLng(bus.getLatitude(),bus.getLongitude())) 
				&& DistanceUtil.getDistance(new LatLng(bus.getLatitude(),bus.getLongitude()), startPos)>10){
			return new LatLng(bus.getLatitude(),bus.getLongitude());
		}
	}
	
	return null;
}
 
开发者ID:Mrsunsunshine,项目名称:FrontOne,代码行数:28,代码来源:BusLineActivity.java

示例8: isBusNear

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
/**
 * 判断车辆是否快抵达此站
 * @return
 */
private boolean isBusNear(Bus bus, int position){
	//TODO 判断公交车是否在此站之前,上一个站点之后
	LatLng startPos = mBusLineList.get(position-1).getLocation();
	LatLng endPos = mBusLineList.get(position).getLocation();
	
	LatLng cricleCenter = new LatLng((startPos.latitude+endPos.latitude)/2,
			(startPos.longitude+endPos.longitude)/2);
	
	if(SpatialRelationUtil.isCircleContainsPoint(cricleCenter,
			(int) DistanceUtil.getDistance(startPos, endPos)/2, 
			new LatLng(bus.getLatitude(),bus.getLongitude()))
			&& DistanceUtil.getDistance(new LatLng(bus.getLatitude(),bus.getLongitude()), startPos)>10){
		return true;
	}
	
	return false;
}
 
开发者ID:Mrsunsunshine,项目名称:FrontOne,代码行数:22,代码来源:BusLineListViewAdapter.java

示例9: getView

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
        convertView = LayoutInflater.from(context).inflate(R.layout.poisearch_item, null);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    PoiInfo poiInfo = poiInfos.get(position);
    holder.poisearch_name.setText(poiInfo.name);
    holder.poisearch_address.setText(poiInfo.address);
    holder.poisearch_distance.setText((int)DistanceUtil.getDistance(locationLatLng, poiInfo.location)+"米");
    return convertView;
}
 
开发者ID:scp504677840,项目名称:MoveMapLocation,代码行数:17,代码来源:PoiSearchAdapter.java

示例10: launchNavigatorViaPoints

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
private static void launchNavigatorViaPoints(final Activity activity, LatLng startLL, LatLng endLL) {
    //这里给出一个起终点示例,实际应用中可以通过POI检索、外部POI来源等方式获取起终点坐标

    final BNRoutePlanNode sNode = new BNRoutePlanNode(startLL.longitude, startLL.latitude, null, "从这里开始", BNRoutePlanNode.CoordinateType.BD09LL);
    final BNRoutePlanNode eNode = new BNRoutePlanNode(endLL.longitude, endLL.latitude, null, "到这里结束", BNRoutePlanNode.CoordinateType.BD09LL);
    if (sNode != null && eNode != null) {
        List<BNRoutePlanNode> points = new ArrayList<BNRoutePlanNode>();
        points.add(sNode);
        points.add(eNode);
        //距离太近toast提示(100米内)
        double dis = DistanceUtil.getDistance(new LatLng(sNode.getLatitude(), sNode.getLongitude()), new LatLng(eNode.getLatitude(), eNode.getLongitude()));
        if (dis <= 100) {
            Toast.makeText(activity, "起点、途经点、终点距离太近", Toast.LENGTH_SHORT).show();
            return;
        }
        BaiduNaviManager.getInstance().launchNavigator(activity, points, 1, true, new BaiduNaviManager.RoutePlanListener() {
            public void onJumpToNavigator() {
        /*
         * 设置途径点以及resetEndNode会回调该接口
*/
                for (Activity ac : activityList) {
                    if (ac.getClass().getName().endsWith("BNDemoGuideActivity")) {
                        return;
                    }
                }
                Intent intent = new Intent(activity, BDInnerNaviActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable(ROUTE_PLAN_NODE, (BNRoutePlanNode) sNode);
                intent.putExtras(bundle);
                activity.startActivity(intent);
            }

            public void onRoutePlanFailed() {
                // TODO Auto-generated method stub
                Toast.makeText(activity, "算路失败", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:NavUtil.java

示例11: zoomToRouteBound

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
public void zoomToRouteBound(BNRoutePlanNode start, BNRoutePlanNode end) {
    LatLng ws = new LatLng(start.getLatitude(), start.getLongitude());
    LatLng we = new LatLng(start.getLatitude(), end.getLongitude());
    int hd = (int) DistanceUtil.getDistance(ws, we);

    LatLng hs = new LatLng(start.getLatitude(), start.getLongitude());
    LatLng he = new LatLng(end.getLatitude(), start.getLongitude());
    int vd = (int) DistanceUtil.getDistance(hs, he);
    //Log.e(TAG,"hd="+hd+",vd="+vd);
    int level = getScales(hd, vd, Math.min(start.getLatitude(), end.getLatitude()));
    MapStatusProxy ms = BNMapControllerProxy.getInstance().getMapStatus();
    //Log.e(TAG,"level="+level);
    ms._Level = level;
    double cLatitude = Math.min(start.getLatitude(), end.getLatitude()) + Math.abs((start.getLatitude() - end.getLatitude()) / 2);
    double cLogitude = Math.min(start.getLongitude(), end.getLongitude()) + Math.abs((start.getLongitude() - end.getLongitude()) / 2);
    //Log.e(TAG,"lat="+cLatitude+",lng="+cLogitude);
    Bundle b1 = ZeroZeroProxy.bala2((int) (cLogitude * 1e5), (int) (cLatitude * 1e5));
    if (b1 != null) {
        ms._CenterPtX = b1.getInt("MCx");
        ms._CenterPtY = b1.getInt("MCy");
    }
    /*if (!BNavigatorProxy.getInstance().isNaviBegin()) {
        _Yoffest = 205;
        _Xoffest = 45;
    } else {
        _Yoffest = 60;
        _Xoffest = 30;
    }
    ms._Yoffset = ScreenUtil.getInstance().dip2px(_Yoffest);
    ms._Xoffset = 0 - ScreenUtil.getInstance().dip2px(_Xoffest);*/
    if (!BNavigatorProxy.getInstance().isNaviBegin())
        ms._Yoffset = ScreenUtil.getInstance().dip2px(100);

    BNMapControllerProxy.getInstance().setMapStatus(ms, BNMapControllerProxy.AnimationType.eAnimationLevel);
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:36,代码来源:BaiduNaviSuperManager.java

示例12: instantiateItem

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
@Override
public Object instantiateItem(ViewGroup container, int position) {
    View itemView = chilren.get(position);
    BaiduAddress address = aList.get(position);
    PagerHolder holder = null;
    /* 加载视图 */
    if (itemView == null) {
        itemView = mInflater.inflate(R.layout.target_poi_item_detail, null);
        chilren.put(position, itemView);
    }
    /* 绑定数据 */
    holder = new PagerHolder(itemView);
    holder.mTpidFavoriteBt.setTag(position);
    holder.mTpidSetTargetBt.setTag(position);
    holder.mTpidTargetConfirmBt.setTag(position);
    holder.mTpidNameText.setText((position + 1) + "." + address.getName());
    holder.mTpidAddressText.setText(address.getAddress());
    Double distance = DistanceUtil.getDistance(new LatLng(address.getLatitude(), address.getLongitude()),
            new LatLng(address.getLatitude(), address.getLongitude())) / 1000;
    holder.mTpidDistanceText.setText(String.format("%.1f", distance) + "km");
    if (address.getFavoritedTime() != null) {
        holder.mTpidFavoriteBt.setText("已收藏");
        holder.mTpidFavoriteBt.getBackground().setLevel(1);
    }

    container.addView(itemView);
    return chilren.get(position);
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:29,代码来源:NaviConfirmPointActivity.java

示例13: onBindViewHolder

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
@Override
public void onBindViewHolder(NaviPointHolder holder, int position) {
    PoiInfo poiInfo = poiInfoList.get(position);
    holder.mTpiNameText.setText((position + 1) + "." + poiInfo.name);
    holder.mTpiAddressText.setText(poiInfo.address);

    holder.mTpiItemConfirmText.setText("出发");
    holder.mTpiDistanceText.setVisibility(View.VISIBLE);
    double distance = DistanceUtil.getDistance(new LatLng(address.getLatitude(), address.getLongitude()),
            poiInfo.location) / 1000;
    holder.mTpiDistanceText.setText(String.format("%.1f", distance) + "km");

    holder.mTpiTargetConfirmBt.setTag(position);
    holder.itemView.setTag(position);
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:16,代码来源:TrafficShowPresenter.java

示例14: instantiateItem

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
@Override
public Object instantiateItem(ViewGroup container, int position) {
    Log.i(TAG, "instantiateItem>>>" + position);
    View child = chilren.get(position);
    if (child == null) {
        child = inflater.inflate(R.layout.target_poi_item_detail, null);
        chilren.put(position, child);
    }
    child.findViewById(R.id.tpid_target_confirm_bt).setOnClickListener(clickListener);
    child.findViewById(R.id.tpid_target_confirm_bt).setTag(position);
    ((TextView) child.findViewById(R.id.tpid_name_text)).setText((position + 1) + "." + aList.get(position).getName());
    ((TextView) child.findViewById(R.id.tpid_address_text)).setText(aList.get(position).getAddress());
    Double distance = DistanceUtil.getDistance(new LatLng(address.getLatitude(), address.getLongitude()),
            poiInfoList.get(position).location) / 1000;
    ((TextView) child.findViewById(R.id.tpid_distance_text)).setText(String.format("%.1f", distance) + "km");
    child.findViewById(R.id.tpid_set_target_bt).setOnClickListener(clickListener);
    child.findViewById(R.id.tpid_set_target_bt).setTag(position);
    TextView ft = (TextView) child.findViewById(R.id.tpid_favorite_bt);
    ft.setOnClickListener(clickListener);
    ft.setTag(position);
    if (aList.get(position).getFavoritedTime() != null) {
        ft.setText("已收藏");
        ((LevelListDrawable) ft.getBackground()).setLevel(1);
    }
    container.addView(child, 0);
    return chilren.get(position);
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:28,代码来源:TrafficShowPresenter.java

示例15: toHomeNavi

import com.baidu.mapapi.utils.DistanceUtil; //导入依赖的package包/类
@Override
public void toHomeNavi() {
    BDLocation bl = new BDLocation();
    bl.setLatitude(address.getLatitude());
    bl.setLongitude(address.getLongitude());
    // bl = LocationClient.getBDLocationInCoorType(bl, BDLocation.BDLOCATION_GCJ02_TO_BD09LL);
    double dt = DistanceUtil.getDistance(new LatLng(bl.getLatitude(), bl.getLongitude()), new LatLng(homeAddress.getLatitude(), homeAddress.getLongitude()));
    if (dt < 50) {
        mSetPointView.showSnackBar(mAppConfig.getResources().getString(R.string.inHome));
        // Toast.makeText(mContext, mAppConfig.getResources().getString(R.string.inHome), Toast.LENGTH_SHORT).show();
    }//else if(dt>100000){
    //            Toast.makeText(mContext, mAppConfig.getResources().getString(R.string.tooLongForCalculate), Toast.LENGTH_SHORT).show();
    //        }
    else {
        //没有网络进行提示
        if (NetUtil.getInstance(mContext).getCurrentNetType().equals(NetUtil.NetType.NETWORK_TYPE_NONE)) {
            final CommonDialog commonDialog = new CommonDialog(mContext, "网络错误", "网络状态不佳,请检查网络设置", "确定");
            commonDialog.setOnConfirmListener(new CommonDialog.OnConfirmListener() {
                @Override
                public void onConfirm() {
                    commonDialog.cancel();
                }
            }).show();
            return;
        }
        Intent intent = new Intent(mContext, NaviSetLineActivity.class);
        intent.putExtra("latitude", homeAddress.getLatitude());
        intent.putExtra("longitude", homeAddress.getLongitude());
        intent.putExtra("address", homeAddress.getName());
        mContext.startActivity(intent);
        mContext.goInto();
    }
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:34,代码来源:NaviSetPointPresenter.java


注:本文中的com.baidu.mapapi.utils.DistanceUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。