1 0 0

v 5-GPS时实获取位置

仙鹤
7月前 455


类模块
double longitude
double latitude

导入类
android.location.LocationManager
android.location.Location
android.content.Context
android.location.LocationListener
android.os.Bundle
android.location.Geocoder
java.util.Locale
android.location.Address
java.lang.String
java.util.List
java.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)
  • V iapp 7月前
    0 引用 2

    大佬发力了

请先登录后发表评论!

返回
请先登录后发表评论!