【发布时间】:2026-01-22 04:20:05
【问题描述】:
可能重复:
What is the simplest and most robust way to get the user’s current location in Android?
我有以下代码可以在手机上打开 Google 地图,并将目的地的经度 + 纬度和起始位置传递给它。我想知道是否有一种方法可以让我们不必手动在代码中输入起始位置,而是以某种方式让代码自动找出用户的位置?
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent (android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + 51.5171 +
"," + 0.1062 + "&daddr=" + 52.6342 + "," + 1.1385));
intent.setComponent(
new ComponentName ("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity"));
startActivity(intent);
}
});
【问题讨论】:
标签: java android google-maps latitude-longitude