v5-GPS时实获取位置

类模块double longitudedouble latitude导入类android.location.LocationManagerandroid.location.Locationandroid.content.Contextandroid.location.LocationListenerandroid.os.Bundleandroid.location.Geocoderjava.util.Localeandroid.location.Addressjava.lang.Stringjava.util.Listjava.io.IOException载入代码//仙鹤开源gd i.runlibrary.app.v.wb wb1=st.wb(zy.id.wb1)java { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { Geocoder geocoder = new Geocoder(main.this, Locale.getDefault()); latitude = location.getLatitude(); // 获取纬度 longitude = location.getLongitude(); // 获取经度 try { List addresses = geocoder.getFromLocation(latitude, longitude, 1); if (addresses.size() > 0) { Address address = addresses.get(0); String locationName = address.getCountryName() + address.getAdminArea() + address.getLocality(); // 获取位置名称 gj.sc(locationName); wb1.zf(locationName); } } catch (IOException e) { e.printStackTrace(); } } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); }

图片[1]-v5-GPS时实获取位置-煜龙论坛观天下

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    请登录后查看评论内容