我的代码是
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 输入的地方。
答案 0 :(得分:2)
试试这个:
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);
答案 1 :(得分:2)
尝试制作如下内容:
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);
请给我一些反馈希望有所帮助。
答案 2 :(得分:0)
您可以通过以下步骤绘制路线: 1 - 从LatLng类型创建列表,并在其中添加导航路径 2-使用如下代码 PolylineOptions options = new PolylineOptions(); options.addAll(“把你的列表放在这里”)。color(Color.BLUE).width(4); 折线navigateRoute =“你的谷歌地图对象”.addPolyline(选项);