- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试在按钮点击中获取位置。我编写了 LocationListener
方法并且一切正常。这是我的来源
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
editLocation.setText("");
pb.setVisibility(View.INVISIBLE);
Toast.makeText(
getBaseContext(),
"Location changed: Lat: " + loc.getLatitude() + " Lng: "
+ loc.getLongitude(), Toast.LENGTH_SHORT).show();
String longitude = "Longitude: " + loc.getLongitude();
Log.v(TAG, longitude);
String latitude = "Latitude: " + loc.getLatitude();
Log.v(TAG, latitude);
/*------- To get city name from coordinates -------- */
String cityName = null;
Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
List<Address> addresses;
try {
addresses = gcd.getFromLocation(loc.getLatitude(),
loc.getLongitude(), 1);
if (addresses.size() > 0) {
System.out.println(addresses.get(0).getLocality());
cityName = addresses.get(0).getLocality();
}
}
catch (IOException e) {
e.printStackTrace();
}
String s = longitude + "\n" + latitude + "\n\nMy Current City is: "
+ cityName;
editLocation.setText(s);
}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}
我可以使用 LocationListener
检查纬度和经度,但是如何在单击按钮时获取当前位置?
最佳答案
您从 LocationManager::getLastKnownLocation() 获取它
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
关于Android在按钮点击中获取位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42890570/
我遇到了一个问题,我无法将网络请求发送到我创建的 Docker 容器。我已经公开了正确的端口,所以我不确定这里可能有哪些其他问题。 我有一台服务器在容器中运行 alice在 localhost:100
在下面最后一行的方法中,我总是遇到异常: System.OverflowException: Value was either too large or too small for an Int32.
我正在关注 realpython article about running Flask on Ubuntu .建议在文章中检查 nginx 已通过导航到 http://localhost:8000/
给定一个条件,我想搜索一个元素列表并返回第一个达到条件的元素和前一个元素。 在 C/C++ 中,这很容易: int i = 0; for(;;i++) if (arr[i] == 0) break;
我正在使用 Firebase Firestore 我想从数据库中删除数据..删除数据工作正常,但我的进度对话框卡住了。我想我必须使用工作线程,但我不知道如何使用。 db = FirebaseFire
我按照 this page 上的说明进行操作创建推送通知。我之前实际上已经做过一次并且能够让它工作(几周前),花了一些时间,我想我现在才再次做这个教程作为复习,出于某种原因,我可以'甚至获取代码以点击
我在大学学习Java,这是我的任务。任务是创建一个由颜色方块组成的x x y网格,每个网格在单独的线程中运行,并且每k ms要么将其颜色更改为随机的颜色,要么对其邻居的颜色求平均。 现在,如果我创建一
我有一台服务器,它不断地从自身获得随机命中,IP 读取为 127.0.0.1 .我知道有各种各样的程序可以做到这一点,但服务器是带有 sendmail 和 monit 的最低限度的 LAMP 服务器。
我正在使用 sqlite 数据库并且我在这个要点中声明了模型 https://gist.github.com/mmahesh/7245561 我添加了一个带有事务管理器的模型实例作为 with tra
我是一名优秀的程序员,十分优秀!