从头学android_LocationManager的使用

来源:互联网 发布:centos wget 命令 编辑:程序博客网 时间:2024/06/05 02:51

android 官方提供了位置管理的API,LocationManager,可以使用3g,wifi,gps能技术定位,但是由于各种原因,得到的坐标是火星坐标,真实的项目开发中还是应该使用百度地图,高德地图等第三方地图巨头提供的API。

/**得到位置管理器*/LocationManager mLM = (LocationManager) getSystemService(LOCATION_SERVICE);mLM.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, new LocationListener() {    /**当位置发生改变的时候调用此方法*/    @Override    public void onLocationChanged(Location location) {        String jingdu = "经度" + location.getLongitude();        String weidu = "纬度" + location.getLatitude();        String haiba = "海拔" + location.getAltitude();        String wucha = "误差" + location.getAccuracy();        String text = jingdu + "\n" + weidu + "\n" + haiba + "\n" + wucha + "\n";        System.out.println(text);  }    @Override    public void onStatusChanged(String s, int i, Bundle bundle) {    }    @Override    public void onProviderEnabled(String s) {    }    @Override    public void onProviderDisabled(String s) {    }});



0 0
原创粉丝点击