栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从LocationListener中设置为double

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从LocationListener中设置为double

// try thispublic static LocationManager mlocManager;public static LocationListner mListner;private static String latitude;public static String longitude;private Location currentLocation;public Location getCurrentLocation() {  return currentLocation;}public void setCurrentLocation(Location currentLocation) {   this.currentLocation = currentLocation;}try {mlocManager = (LocationManager) getSystemService(Activity.LOCATION_SERVICE);     mListner = new LocationListner();     runonUiThread(new Runnable() {         @Override         public void run() {  try {  try {      mlocManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, mListner);  } catch (Throwable e) {      e.printStackTrace();  }      mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mListner);  } catch (Throwable e) {      e.printStackTrace();  }  try {      mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mListner);  } catch (Throwable e) {      e.printStackTrace();  }         }     });} catch (Throwable e) {    e.printStackTrace();}    public String getLatitude() {        if (latitude != null) { return latitude;        }        Location loc = mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);        if (loc == null) { loc = mlocManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (loc == null) {     loc = mlocManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } if (loc != null) {     return "" + loc.getLatitude(); }        } else { return "" + loc.getLatitude();        }        return "0.0";    }    public void setLatitude(String latitide) {        latitude = latitide;    }    public String getLongitude() {        if (longitude != null) { return longitude;        }        Location loc = mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);        if (loc == null) { loc = mlocManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (loc == null) {     loc = mlocManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } if (loc != null) {     return "" + loc.getLongitude(); }        } else { return "" + loc.getLongitude();        }        return "0.0";    }    public void setLongitude(String longitude) {        SmartActivity.longitude = longitude;    }    class LocationListner implements LocationListener {        @Override        public void onLocationChanged(Location location) { setLatitude("" + location.getLatitude()); setLongitude("" + location.getLongitude()); setCurrentLocation(location);        }        @Override        public void onProviderDisabled(String provider) {        }        @Override        public void onProviderEnabled(String provider) {        }        @Override        public void onStatusChanged(String provider, int status, Bundle extras) {        }    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/595569.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号