我的代码是
public class RouteMap extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up GUI
setContentView(R.layout.main);
// Reference edit field
final EditText addressfield = (EditText) findViewById(R.id.address);
final EditText addressfield1 = (EditText) findViewById(R.id.address1);
// Reference search button
final Button launchmapbtn = (Button) findViewById(R.id.launchmap);
launchmapbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
// Get source address
String address = addressfield.getText().toString();
address = address.replace(' ', '+');
// Get Destination address
String address1 = addressfield1.getText().toString();
address1 = address1.replace(' ', '+');
// Prepare intent
Intent geoIntent = new Intent(
android.content.Intent.ACTION_VIEW, Uri
.parse("geo:0,0?q=" + address + ","
+ address1));
// Initiate lookup
startActivity(geoIntent);
} catch (Exception e) {
}
}
});
}
}
但是我无法得到两个地方之间的 map 。
我想获取两地之间的路线图。用户使用 EditText 输入的位置。
最佳答案
试试这个:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + point1_lat + ","
+ point1_lng + "&daddr=" + point2_latitude + "," + point2_longitude + ""));
startActivity(intent);
或者如果你想放置标记然后在下面使用:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:55.74274,37.56577?q=55.74274,37.56577 (name)"));
intent.setComponent(new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"));
startActivity(intent);
关于android - 如何使用intent Android绘制路线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21674352/