原创

gps定位,根据经纬度;

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_38998213/article/details/81676742
String[] permissions={"android.permission.ACCESS_COARSE_LOCATION","android.permission.INTERNET","android.permission.ACCESS_FINE_LOCATION"};
ActivityCompat.requestPermissions(this,permissions,1);
String[] permissions_loc={"android.permission.ACCESS_FINE_LOCATION"};
ActivityCompat.requestPermissions(this,permissions_loc,2);
String[] permissions_net={"android.permission.INTERNET"};
ActivityCompat.requestPermissions(this,permissions_net,3);

 

动态获取权限,Gpa需要动态的获取;

 

 public String updateWithNewLocation(String lat, String lng) {
        String latLongString = null;
        TextView myLocationText;

        List<Address> addList = null;
        Geocoder ge = new Geocoder(this);
        try {
            if (lat != null && lng != null) {
                double lat_d = Double.parseDouble(lat.toString());
                double lng_d = Double.parseDouble(lng.toString());
//            double lat_d=36;
//            double lng_d=117;
                addList = ge.getFromLocation(lat_d, lng_d, 1);
            } else {
                latLongString = getResources().getString(R.string.no_local);
            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (addList != null && addList.size() > 0) {
            for (int i = 0; i < addList.size(); i++) {
                Address ad = addList.get(i);
                latLongString = ad.getCountryName() + "●" + ad.getLocality();
                System.out.print(latLongString);
            }
        } else {
            latLongString = getResources().getString(R.string.no_local);
        }
        return latLongString;
    }

 

展开阅读全文

没有更多推荐了,返回首页