close

承上篇

加入導航路線規劃,一併判斷定位點

因為我是公用呼叫的 所以activity要傳進來

public void onNavigation(Activity a,final String address)
{
      this.activity = a;
      loactionManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);

      //GPS 定位
      loaction = loactionManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

      //判斷是否開啟GPS
      if(openGPSSettings()){

            //定位點為NULL
            if(loaction==null){
                  Toast.makeText(activity,"目前您所在的位置無法取得定位點,請稍後在試!", 5000).show();
            }
            else{
                  double geoLatitude = loaction.getLatitude();
                  double geoLongitude = loaction.getLongitude();

                  //呼叫google內建地圖---saddr 起點, daddr-終點, dirflg 規劃路線(d-駕車, r-乘車, w-步行)
                  Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("http://ditu.google.cn/maps?
                  f=d&source=s_d&saddr="+geoLatitude+","+geoLongitude+"&daddr="+address+"&hl=zh& t=m&dirflg=d"));

                  System.out.println("geoLatitude:"+geoLatitude+"geoLongitude:"+geoLongitude);
                  i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                  i.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
                  activity.startActivity(i);
            }
      }
}

arrow
arrow
    文章標籤
    android GPS
    全站熱搜
    創作者介紹
    創作者 鴨鴨仔 的頭像
    鴨鴨仔

    DUCK,Fearless!

    鴨鴨仔 發表在 痞客邦 留言(0) 人氣()