【问题标题】:get a constant update of longitude and latitude from google maps [duplicate]从谷歌地图获取经度和纬度的不断更新[重复]
【发布时间】:2020-04-05 10:41:20
【问题描述】:

所以我正在尝试制作一个按钮来显示我当前的经度和纬度,并在我移动时显示我的新经度和纬度,我正在尝试使用谷歌地图 API 来做到这一点。我正在尝试通读文档,但没有看到任何可用的方法。另外,我是 android 编码的新手,所以我不知道编写文档的方式是否不同。我看到了使用 Location_Manager 的教程,所以我认为我不需要使用 Google。请帮帮我,我在这里撞墙了。

【问题讨论】:

  • 您必须自己通过每秒获取位置来完成此操作。地图不会为您提供这些
  • 你必须使用Location_Manager。
  • 如果您使用的是 kotlin,请查看Here。它还支持安卓10。

标签: android google-maps-api-3 android-gps


【解决方案1】:

点击按钮获取当前 GPS 坐标的代码

    LocationManager mLocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
            LocationListener mLocListener = new MyLocationListener();
            mLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocListener);

    public class MyLocationListener implements LocationListener{        

    public void onLocationChanged(Location loc) {           
        String message = String.format(
                    "New Location \n Longitude: %1$s \n Latitude: %2$s",
                    loc.getLongitude(), loc.getLatitude()
            );
            Toast.makeText(LbsGeocodingActivity.this, message, Toast.LENGTH_LONG).show();
    }
    public void onProviderDisabled(String arg0) {

    }
    public void onProviderEnabled(String provider) {

    }
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }       
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多