android - 从谷歌地图获取经度和纬度的不断更新
问题描述
所以我正在尝试制作一个按钮来显示我当前的经度和纬度,并在我移动时显示我的新经度和纬度,我正在尝试使用谷歌地图 API 来做到这一点。我正在尝试通读文档,但没有看到任何可用的方法。另外,我是 android 编码的新手,所以我不知道编写文档的方式是否不同。我看到了使用 Location_Manager 的教程,所以我认为我不需要使用 Google。请帮助我在墙上。
解决方案
单击按钮获取当前 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) {
}
}
推荐阅读
- python-3.x - 删除具有多个值的字典键值
- php - 如何动态设置 PHP const 变量?
- flask - heroku 应用程序成功部署但显示应用程序错误
- javascript - Bootstrap scrollspy 在刷新页面时无法正常工作
- php - 用php隐藏带有0查询值的输出
- .net - 数据库中已经有一个名为“Servicio”的对象
- amazon-web-services - 如何分配内存以用作 Amazon EC2 上的交换空间?
- arrays - 数组中元素的总和和平均值?
- networkx - 从过滤边的 subgraph_view 中获取 networkx 过滤节点
- java - 调用newthread后如何获取线程索引?