2015年4月22日 星期三

【Android】使用 Intent 呼叫 google maps 進行導航



double startLatitude = 24.772018;
double startLongitude = 121.002129;

double endLatitude = 24.7909902;
double endLongitude = 121.0024402;

String saddr = "saddr=" + startLatitude + "," + startLongitude;
String daddr = "daddr=" + endLatitude + "," + endLongitude;
String uriString = "http://maps.google.com/maps?" + saddr + "&" + daddr;

Uri uri = Uri.parse(uriString);

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);

// If you want to get rid of the dialog,
// Before the startActivity() add this
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");

startActivity(intent);

沒有留言:

張貼留言