您当前的位置: Android HUD SDK > 开发指南 > 目的地
目的地

概述

本次导航当前位置距离目的地剩下的距离及时间信息,如下图所示:

guide_termination.png

关键代码

@Override
public void onRemainInfo(BNRGRemainInfo arg0) {
	Log.d(BNRemoteConstants.MODULE_TAG, "onRemainInfo.............distance = " + arg0.getRemainDistance() + ", time = " + arg0.getRemainTime());
 
	final String remainDistance = calculateTotalRemainDistString(arg0.getRemainDistance());
	final String remainTime = calculateArriveTime(arg0.getRemainTime());
	mMainHandler.post(new Runnable() {
 
		@Override
		public void run() {
			mTotalDistTV.setText(remainDistance);
			mArriveTimeTV.setText(remainTime);
		}
	});
}
 
private String calculateTotalRemainDistString(int nDist) {
	StringBuffer builder = new StringBuffer();
	StringUtils.formatDistance(nDist, UnitLangEnum.ZH, builder);
	String totalRemainDistS = builder.toString();
 
	return totalRemainDistS;
}
 
private String calculateArriveTime(int remainTime) {
	long mArriveTime = System.currentTimeMillis();
	Date curDate = new Date(mArriveTime);
	mArriveTime += ( remainTime * 1000 );
	Date arriveDate = new Date(mArriveTime);
 
	SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
	String mArriveTimeS = sdf.format(arriveDate);
 
    GregorianCalendar curCal = new GregorianCalendar();
    curCal.setTime(curDate);
    GregorianCalendar arriveCal = new GregorianCalendar();
    arriveCal.setTime(arriveDate);
 
	if ( curCal.get(GregorianCalendar.DAY_OF_MONTH) == arriveCal.get(GregorianCalendar.DAY_OF_MONTH) ) {
        if ( 0 == arriveCal.get(GregorianCalendar.HOUR_OF_DAY)) {
            mArriveTimeS = String.format(getString(R.string.nsdk_string_rg_arrive_time_at_wee), mArriveTimeS);
        } else {
            mArriveTimeS = String.format(getString(R.string.nsdk_string_rg_arrive_time), mArriveTimeS);
        }
	} else {
		int interval = getIntervalDays(curDate, arriveDate);
		if( interval == 1 ) {
            if ( arriveCal.get(GregorianCalendar.HOUR_OF_DAY) >= 0 && arriveCal.get(GregorianCalendar.HOUR_OF_DAY) < 4 ) {
                mArriveTimeS = String.format(getString(R.string.nsdk_string_rg_arrive_time),getString(R.string.nsdk_string_rg_wee_hours));
            } else {
                mArriveTimeS = String.format(getString(R.string.nsdk_string_rg_arrive_time),
                        getString(R.string.nsdk_string_rg_tomorrow));
            }
		} else if ( interval == 2 ) {
			mArriveTimeS = String.format(getString(R.string.nsdk_string_rg_arrive_time), 
					getString(R.string.nsdk_string_rg_the_day_after_tomorrow));
		} else if ( interval > 2 ) {
			mArriveTimeS = String.format(getString(R.string.nsdk_string_rg_arrive_time_after_day), "" + interval);
		} else {
			mArriveTimeS = String.format(getString(R.string.nsdk_string_rg_arrive_time), mArriveTimeS);
		}
	}
 
	return mArriveTimeS;
}