簡體   English   中英

如何使用Intent Android繪制路線圖

[英]how to draw route map using intent 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) {

                }
            }
        });
    }
}

但是我無法獲得兩個地方之間的地圖。

我想獲取兩個地方之間的路線圖。 用戶使用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);

嘗試使類似以下內容的東西:

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

請給我一些反饋

希望對您有所幫助。

您可以通過執行以下步驟來繪制路線:1-從LatLng類型創建列表並在其中添加導航路徑2-使用類似以下PolylineOptions options = new PolylineOptions()的代碼; options.addAll(“在此輸入您的列表”).color(Color.BLUE).width(4); 折線NavigatorRoute =“您的谷歌地圖對象”。addPolyline(options);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM