简体   繁体   English

如何使用Intent Android绘制路线图

[英]how to draw route map using intent Android

My code is 我的代码是

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) {

                }
            }
        });
    }
}

But I can't get the map between two places. 但是我无法获得两个地方之间的地图。

I want to get the route map between two places. 我想获取两个地方之间的路线图。 The place entered using EditText by the user. 用户使用EditText输入的位置。

try this: 尝试这个:

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);

Or if you want to place mark then used below: 或者,如果您想放置标记,请在下面使用:

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);

try to mke something like the following : 尝试使类似以下内容的东西:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
    Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);

please give me some feedback 请给我一些反馈

Hope that Helps . 希望对您有所帮助。

You can draw your route by making the following steps: 1-create list from type LatLng and add your navigation paths inside it 2- use code like the following PolylineOptions options = new PolylineOptions(); 您可以通过执行以下步骤来绘制路线:1-从LatLng类型创建列表并在其中添加导航路径2-使用类似以下PolylineOptions options = new PolylineOptions()的代码; options.addAll("put your list here").color(Color.BLUE).width(4); options.addAll(“在此输入您的列表”).color(Color.BLUE).width(4); Polyline navigateRoute = "your google map object".addPolyline(options); 折线NavigatorRoute =“您的谷歌地图对象”。addPolyline(options);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM