1

我正在尝试实现一个功能,这样当用户在文本字段中输入地址并单击按钮时,该地址应复制到 Google 地图的目标字段中,并且用户位置应设置为“我的位置”(他现在的位置)。

4

2 回答 2

4

您可以通过以下方式打开谷歌地图:

String CURRENT_LOCATION = "current_location_latitude, current_location_longitude";
String DESTINATION_LOCATION = "address_from_your_text_view";

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+ CURRENT_LOCATION +" daddr="+DESTINATION_LOCATION));
startActivity(intent);

注意:您应该从 LocationManager 获取设备/用户当前位置

于 2013-03-05T07:23:07.583 回答
2

为了在谷歌地图上显示路线,只需调用一个通过当前和目的地纬度和经度的意图。如果不知道经纬度,您也可以在任何情况下传递地址。这样做之后,它的谷歌地图的工作就是显示位置。您还可以显示街景。

在下面的代码中,有三个参数:current_lat, current_longi, dest_address

 final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?" 
+ "saddr="+ current_lat+","+current_longi + "&daddr="+dest_address ));

intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");

startActivity(intent); 

如果你有当前地址和目标地址,那么你可以这样写:

Uri.parse("http://maps.google.com/maps?" 
+ "saddr="+curr_address+ "&daddr="+dest_address ));

如果你有当前和目的地的纬度和经度,那么你可以这样写:

Uri.parse("http://maps.google.com/maps?" 
+ "saddr="+ current_lat+","+current_longi + "&daddr="+ destt_lat+","+dest_longi  ));

当你调用这个意图时,谷歌地图会显示选择是通过公共汽车还是步行来绘制路线。

于 2013-03-05T07:13:38.420 回答