android - 如何使用intent Android绘制路线图

标签 android

我的代码是

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/

相关文章:

javascript - 在 cordova 中以独立于平台的方式访问数据目录

android - 非法状态异常 : Fragment already added; unable to figure out exact reason and location from fabric log

android - 如何在视频渲染案例中使用 ImageView 进行高效处理?

android - 如何使用保存实例状态保存 Activity 状态?

java - 使用android从字母数字字符串中提取数字

android - 使用 Mockito 进行 Retrofit 2 api 调用的单元测试

java - Android Adapter的convertview未更新

android - View 类中的 Hashcode() 和 equals() 实现

Android:同步传感器和 GPS 的时间戳

android - Android编程中空值逻辑: Confused