Esempio n. 1
0
  /** 调用百度地图客户端导航 */
  private void startNaviByClient() {
    double mLat1 = userLoc.getLatitude();
    double mLon1 = userLoc.getLongitude();
    double mLat2 = destLoc.getLatitude();
    double mLon2 = destLoc.getLongitude();

    LatLng p1 = new LatLng(mLat1, mLon1);
    LatLng p2 = new LatLng(mLat2, mLon2);

    final NaviParaOption para = new NaviParaOption();
    para.startPoint(p1);
    para.startName("起点");
    para.endPoint(p2);
    para.endName("终点");

    try {
      BaiduMapNavigation.openBaiduMapNavi(para, this);
    } catch (BaiduMapAppNotSupportNaviException e) {
      e.printStackTrace();
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setMessage("您尚未安装百度地图app或app版本过低,点击确认安装?");
      builder.setTitle("提示");
      builder.setPositiveButton(
          "确认",
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
              dialog.dismiss();
              BaiduMapNavigation.openWebBaiduMapNavi(para, NavigateActivity.this);
            }
          });

      builder.setNegativeButton(
          "取消",
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
              dialog.dismiss();
            }
          });

      builder.create().show();
    }
  }
  /**
   * 开始导航
   *
   * @param view
   */
  public void startNavi() {
    try {
      LatLng pt1 = new LatLng(myX, myY); // (hotelY+0.01,hotelX+0.01);
      Log.e("myY-myX", myY + "---" + myX);
      LatLng pt2 = new LatLng(hotelY, hotelX);
      // 构建 导航参数
      NaviPara para = new NaviPara();
      para.startPoint = pt1;
      para.startName = "从这里开始";
      para.endPoint = pt2;
      para.endName = "到这里结束";

      try {
        BaiduMapNavigation.openBaiduMapNavi(para, this);
      } catch (BaiduMapAppNotSupportNaviException e) {
        e.printStackTrace();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("您尚未安装百度地图app或app版本过低,点击确认安装?");
        builder.setTitle("提示");
        builder.setPositiveButton(
            "确认",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                try {
                  dialog.dismiss();
                  BaiduMapNavigation.getLatestBaiduMapApp(ActivityHotelLocation.this);
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            });
        builder.setNegativeButton(
            "取消",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
              }
            });
        builder.create().show();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }