Java Code Examples for com.baidu.mapapi.utils.DistanceUtil#getDistance()

The following examples show how to use com.baidu.mapapi.utils.DistanceUtil#getDistance() . 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: NavUtil.java    From Mobike with Apache License 2.0 6 votes vote down vote up
/**
 * 启动百度地图骑行导航(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();
    }
}
 
Example 2
Source File: FreightTrackMapFragment.java    From ESeal with Apache License 2.0 6 votes vote down vote up
/**
 * 获取百度地图显示等级
 * 范围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;
}
 
Example 3
Source File: FreightTrackGoogleMapFragment.java    From ESeal with Apache License 2.0 6 votes vote down vote up
/**
 * 获取百度地图显示等级
 * 范围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;
}
 
Example 4
Source File: NaviConfirmPointActivity.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 5
Source File: NavUtil.java    From Mobike with Apache License 2.0 6 votes vote down vote up
/**
 * 通过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();
    }
}
 
Example 6
Source File: TrafficShowPresenter.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 7
Source File: FreightTrackMapWithWebViewFragment.java    From ESeal with Apache License 2.0 6 votes vote down vote up
/**
 * 获取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;
}
 
Example 8
Source File: FreightTrackBaiduMapFragment.java    From ESeal with Apache License 2.0 6 votes vote down vote up
/**
 * 获取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;
}
 
Example 9
Source File: BaiduMapFragment.java    From BmapLite with Apache License 2.0 5 votes vote down vote up
public void setRangingPolyLine() {
    if (null == mPoiList || mPoiList.size() < 2) {
        mTotal = 0;
        ((MainActivity) getActivity()).setRangingDistance(mTotal);
        return;
    }

    MyPoiModel end = mPoiList.get(mPoiList.size() - 1);
    MyPoiModel last = mPoiList.get(mPoiList.size() - 2);

    mTotal += DistanceUtil.getDistance(new LatLng(end.getLatitude(), end.getLongitude()),
            new LatLng(last.getLatitude(), last.getLongitude()));

    List<LatLng> points = new ArrayList<>();
    points.add(new LatLng(end.getLatitude(), end.getLongitude()));
    points.add(new LatLng(last.getLatitude(), last.getLongitude()));

    OverlayOptions ooPolyline = new PolylineOptions().width(6).color(Color.BLUE).points(points);
    Overlay line = mBaiduMap.addOverlay(ooPolyline);

    if (mOverlayList == null) {
        mOverlayList = new ArrayList<>();
    }
    mOverlayList.add(line);

    ((MainActivity) getActivity()).setRangingDistance(mTotal);
}
 
Example 10
Source File: TrafficShowPresenter.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 11
Source File: NaviSetPointPresenter.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Override
public void toCompanyNavi() {
    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(companyAddress.getLatitude(), companyAddress.getLongitude()));
    if (dt < 50) {
        mSetPointView.showSnackBar(mAppConfig.getResources().getString(R.string.inCompany));
        //  Toast.makeText(mContext, mAppConfig.getResources().getString(R.string.inCompany), 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", companyAddress.getLatitude());
        intent.putExtra("longitude", companyAddress.getLongitude());
        intent.putExtra("address", companyAddress.getName());
        mContext.startActivity(intent);
        mContext.goInto();
    }

}
 
Example 12
Source File: RouteActivity.java    From BmapLite with Apache License 2.0 5 votes vote down vote up
public int getDistance() {
    if (null == mPoiStart || null == mPoiEnd) {
        return 0;
    }
    return (int) DistanceUtil.getDistance(new LatLng(mPoiStart.getLatitude(), mPoiStart.getLongitude()),
            new LatLng(mPoiEnd.getLatitude(), mPoiEnd.getLongitude()));
}
 
Example 13
Source File: BaiduMapFragment.java    From BmapLite with Apache License 2.0 5 votes vote down vote up
private void makeMarker(MyPoiModel poi, boolean isClear) {
//        if (isClear) {
//            clearMarker();
//        }
//
//        //构建Marker图标
//        BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
//        //构建MarkerOption,用于在地图上添加Marker
//        OverlayOptions option = new MarkerOptions().title(poi.getName()).position(poi.getLatLngBaidu(getActivity())).icon(bitmap).animateType(MarkerOptions.MarkerAnimateType.none);
//        //在地图上添加Marker,并显示
//        mBaiduMap.addOverlay(option);
//
//        MapStatus.Builder builder = new MapStatus.Builder();
//        builder.target(poi.getLatLngBaidu(getActivity()));
//        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));

        makeMarker(poi, isClear, 0);

        int distance = 0;
        if (null != BApp.MY_LOCATION) {
            distance = (int) DistanceUtil.getDistance(new LatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude()),
                    new LatLng(poi.getLatitude(), poi.getLongitude()));
        }

        ((MainActivity) getActivity()).showPoiLay(poi, distance);

    }
 
Example 14
Source File: Adapter_SearchAddress.java    From BaiDuMapSelectDemo with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
        convertView = oInflater.inflate(R.layout.item_search_address, null);
        viewHolder = new ViewHolder();
        //得到各个控件的对象
        viewHolder.iv_point = convertView.findViewById(R.id.iv_point);
        viewHolder.tv_name = convertView.findViewById(R.id.tv_name);
        viewHolder.tv_address = convertView.findViewById(R.id.tv_address);
        viewHolder.tv_distance = convertView.findViewById(R.id.tv_distance);
        //绑定viewHolder对象
        convertView.setTag(viewHolder);

    } else {
        //取出viewHolder对象
        viewHolder = (ViewHolder) convertView.getTag();
    }
    PoiInfo poiInfo = oList.get(position);
    LatLng latLng = poiInfo.getLocation();
    //用当前所在位置算出距离
    double distance=DistanceUtil.getDistance(currentLatLng, latLng);

    viewHolder.tv_name.setText(poiInfo.name);
    viewHolder.tv_address.setText(poiInfo.address);
    viewHolder.tv_distance.setText(formatDistance(distance));
    if (position == 0) {
        viewHolder.iv_point.setImageResource(R.drawable.point_orange);
        viewHolder.tv_name.setTextColor(ocontext.getResources().getColor(R.color.orange));
    }else{
        viewHolder.iv_point.setImageResource(R.drawable.point_gray);
        viewHolder.tv_name.setTextColor(ocontext.getResources().getColor(R.color.black));
    }
    return convertView;
}
 
Example 15
Source File: BaiduMapFragment.java    From BmapLite with GNU General Public License v3.0 5 votes vote down vote up
public void deleteRangingPoi() {
    if (null == mPoiList || mOverlayList == null) {
        return;
    }
    if (mPoiList.size() > 1) {
        MyPoiModel end = mPoiList.get(mPoiList.size() - 1);
        MyPoiModel pre = mPoiList.get(mPoiList.size() - 2);

        mTotal -= DistanceUtil.getDistance(new LatLng(end.getLatitude(), end.getLongitude()), new LatLng(pre.getLatitude(), pre.getLongitude()));

        mPoiList.remove(mPoiList.size() - 1);
        ((MainActivity) getActivity()).setRangingDistance(mTotal);
    } else if (mPoiList.size() == 1) {
        mPoiList.remove(mPoiList.size() - 1);
        mTotal = 0;
        ((MainActivity) getActivity()).setRangingDistance(mTotal);
    }

    if (!mOverlayList.isEmpty()) {
        mOverlayList.get(mOverlayList.size() - 1).remove();
        mOverlayList.remove(mOverlayList.size() - 1);
    }

    if (!mOverlayList.isEmpty()) {
        mOverlayList.get(mOverlayList.size() - 1).remove();
        mOverlayList.remove(mOverlayList.size() - 1);
    }
}
 
Example 16
Source File: BaiduMapFragment.java    From BmapLite with GNU General Public License v3.0 5 votes vote down vote up
public void setRangingPolyLine() {
    if (null == mPoiList || mPoiList.size() < 2) {
        mTotal = 0;
        ((MainActivity) getActivity()).setRangingDistance(mTotal);
        return;
    }

    MyPoiModel end = mPoiList.get(mPoiList.size() - 1);
    MyPoiModel last = mPoiList.get(mPoiList.size() - 2);

    mTotal += DistanceUtil.getDistance(new LatLng(end.getLatitude(), end.getLongitude()),
            new LatLng(last.getLatitude(), last.getLongitude()));

    List<LatLng> points = new ArrayList<>();
    points.add(new LatLng(end.getLatitude(), end.getLongitude()));
    points.add(new LatLng(last.getLatitude(), last.getLongitude()));

    OverlayOptions ooPolyline = new PolylineOptions().width(6).color(Color.BLUE).points(points);
    Overlay line = mBaiduMap.addOverlay(ooPolyline);

    if (mOverlayList == null) {
        mOverlayList = new ArrayList<>();
    }
    mOverlayList.add(line);

    ((MainActivity) getActivity()).setRangingDistance(mTotal);
}
 
Example 17
Source File: BaiduMapFragment.java    From BmapLite with GNU General Public License v3.0 5 votes vote down vote up
private void makeMarker(MyPoiModel poi, boolean isClear) {
//        if (isClear) {
//            clearMarker();
//        }
//
//        //构建Marker图标
//        BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
//        //构建MarkerOption,用于在地图上添加Marker
//        OverlayOptions option = new MarkerOptions().title(poi.getName()).position(poi.getLatLngBaidu(getActivity())).icon(bitmap).animateType(MarkerOptions.MarkerAnimateType.none);
//        //在地图上添加Marker,并显示
//        mBaiduMap.addOverlay(option);
//
//        MapStatus.Builder builder = new MapStatus.Builder();
//        builder.target(poi.getLatLngBaidu(getActivity()));
//        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));

        makeMarker(poi, isClear, 0);

        int distance = 0;
        if (null != BApp.MY_LOCATION) {
            distance = (int) DistanceUtil.getDistance(new LatLng(BApp.MY_LOCATION.getLatitude(), BApp.MY_LOCATION.getLongitude()),
                    new LatLng(poi.getLatitude(), poi.getLongitude()));
        }

        ((MainActivity) getActivity()).showPoiLay(poi, distance);

    }
 
Example 18
Source File: NaviSetPointPresenter.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
/**
 * 更新出发地视图
 */
private void updateStart(boolean toNavi) {
    startAddress = mAppConfig.startAddress;
    if (startAddress != null) {
        System.out.println("updateStart,出发地地址不为空" + startAddress.getName());
        String start = startAddress.getName();
        mSetPointView.setStartAddrText(start);
        //获取数据库中的目的地地址
        BaiduAddress endAddr = mAppConfig.endAddress;
        if (endAddr != null && toNavi) {
            double dt = DistanceUtil.getDistance(new LatLng(startAddress.getLatitude(), startAddress.getLongitude()),
                    new LatLng(endAddr.getLatitude(), endAddr.getLongitude()));
            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;
            }
            if (dt > 50) {
                //                        final CommonAlertDialog progressDialog = new CommonAlertDialog(mContext, "导航引擎", "线路规划中...");
                //                        progressDialog.show();
                final Intent intent = new Intent(mContext, NaviSetLineActivity.class); //你要转向的Activity
                intent.putExtra("start_latitude", startAddress.getLatitude());
                intent.putExtra("start_longitude", startAddress.getLongitude());
                intent.putExtra("start_address", startAddress.getName());
                intent.putExtra("end_latitude", endAddr.getLatitude());
                intent.putExtra("end_longitude", endAddr.getLongitude());
                intent.putExtra("end_address", endAddr.getName());
                NaviRecord record = new NaviRecord();
                record.setStartLatitude(startAddress.getLatitude());
                record.setStartLongitude(startAddress.getLongitude());
                record.setStartName(startAddress.getName());
                record.setEndLatitude(endAddr.getLatitude());
                record.setEndLongitude(endAddr.getLongitude());
                record.setEndName(endAddr.getName());
                record.setCreated(new Date(System.currentTimeMillis()));
                mRecordDao.insertRecord(record);
                //                        Timer timer = new Timer();
                //                        TimerTask task = new TimerTask() {
                //                            @Override
                //                            public void run() {
                mContext.startActivity(intent); //执行
                mContext.goInto();
                //                                progressDialog.cancel();
                //                            }
                //                        };
                //                        timer.schedule(task, 2000); //2秒后
            } else {
                // Toast.makeText(mContext, mAppConfig.getResources().getString(R.string.tooShortForCalculate), Toast.LENGTH_SHORT).show();
                mSetPointView.showSnackBar(mAppConfig.getResources().getString(R.string.tooShortForCalculate));
            }
        }
    } else {
        mSetPointView.setStartAddrText("选择出发地");
    }

}
 
Example 19
Source File: RouteService.java    From Mobike with Apache License 2.0 4 votes vote down vote up
@Override
        public void onReceiveLocation(BDLocation bdLocation) {
            if (null == bdLocation) return;
            //"4.9E-324"表示目前所处的环境(室内或者是网络状况不佳)造成无法获取到经纬度
            if ("4.9E-324".equals(String.valueOf(bdLocation.getLatitude())) || "4.9E-324".equals(String.valueOf(bdLocation.getLongitude()))) {
                return;
            }//过滤百度定位失败

            Log.d("gaolei", "RouteService---------getAddrStr()-------------" + bdLocation.getAddrStr());
            double routeLat = bdLocation.getLatitude();
            double routeLng = bdLocation.getLongitude();
            RoutePoint routePoint = new RoutePoint();
            routePoint.setRouteLat(routeLat);
            routePoint.setRouteLng(routeLng);
            if (routPointList.size() == 0)
                routPointList.add(routePoint);
            else {
                RoutePoint lastPoint = routPointList.get(routPointList.size() - 1);

                if (routeLat == lastPoint.getRouteLat() && routeLng == lastPoint.getRouteLng()) {

                } else {

                    LatLng lastLatLng = new LatLng(lastPoint.getRouteLat(),
                            lastPoint.getRouteLng());
                    LatLng currentLatLng = new LatLng(routeLat, routeLng);
                    if (routeLat > 0 && routeLng > 0) {
                        double distantce = DistanceUtil.getDistance(lastLatLng, currentLatLng);
//                        Log.d("gaolei", "distantce--------------" + distantce);
                        if (distantce > 5) {
                            routPointList.add(routePoint);
                            totalDistance += distantce;
                        }
                    }
                }
            }

            totalTime = (int) (System.currentTimeMillis() - beginTime) / 1000 / 60;
            totalPrice = (float) (Math.floor(totalTime / 30) * 0.5 + 0.5);
//            Log.d("gaolei", "biginTime--------------" + beginTime);
            Log.d("gaolei", "totalTime--------------" + totalTime);
            Log.d("gaolei", "totalDistance--------------" + totalDistance);
            startNotifi(totalTime + "分钟", totalDistance + "米", totalPrice + "元");
            Intent intent = new Intent("com.locationreceiver");
            Bundle bundle = new Bundle();
            bundle.putString("totalTime", totalTime + "分钟");
            bundle.putString("totalDistance", totalDistance + "米");
            bundle.putString("totalPrice", totalPrice + "元");
            intent.putExtras(bundle);
            sendBroadcast(intent);
        }
 
Example 20
Source File: NaviSetPointPresenter.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
/**
 * 更新目的地视图
 */
private void updateEnd(boolean toNavi) {
    endAddress = mAppConfig.endAddress;
    if (endAddress != null) {
        String end = endAddress.getName();
        mSetPointView.setEndAddrText(end);
        BaiduAddress startAddr = mAppConfig.startAddress;
        if (startAddr != null && toNavi) {
            double dt = DistanceUtil.getDistance(new LatLng(startAddr.getLatitude(), startAddr.getLongitude()),
                    new LatLng(endAddress.getLatitude(), endAddress.getLongitude()));
            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;
            }
            if (dt > 50) {
                //                    final CommonAlertDialog progressDialog = new CommonAlertDialog(mContext, "导航引擎", "线路规划中...");
                //                    progressDialog.show();
                final Intent intent = new Intent(mContext, NaviSetLineActivity.class); //你要转向的Activity
                intent.putExtra("start_latitude", startAddr.getLatitude());
                intent.putExtra("start_longitude", startAddr.getLongitude());
                intent.putExtra("start_address", startAddr.getName());
                intent.putExtra("end_latitude", endAddress.getLatitude());
                intent.putExtra("end_longitude", endAddress.getLongitude());
                intent.putExtra("end_address", endAddress.getName());
                NaviRecord record = new NaviRecord();
                record.setStartLatitude(startAddr.getLatitude());
                record.setStartLongitude(startAddr.getLongitude());
                record.setStartName(startAddr.getName());
                record.setEndLatitude(endAddress.getLatitude());
                record.setEndLongitude(endAddress.getLongitude());
                record.setEndName(endAddress.getName());
                record.setCreated(new Date(System.currentTimeMillis()));
                mRecordDao.insertRecord(record);
                Timer timer = new Timer();
                TimerTask task = new TimerTask() {
                    @Override
                    public void run() {
                        mContext.startActivity(intent); //执行
                        mContext.goInto();
                        //                            progressDialog.cancel();
                    }
                };
                timer.schedule(task, 1000); //1秒后
            } else {
                mSetPointView.showSnackBar(mAppConfig.getResources().getString(R.string.tooShortForCalculate));
                //  Toast.makeText(mContext, mAppConfig.getResources().getString(R.string.tooShortForCalculate), Toast.LENGTH_SHORT).show();
            }
        }
    } else {
        mSetPointView.setEndAddrText("选择目的地");
    }
}