大二寒假作业之Android

今日学习了如何获取当前的经纬坐标。

首先要获取服务:LocationManager locationmanager=new (LocationManager)getSystemService(LOCATION_SERVICE);

然后设置定位监听器:locationmanager.requestLocationUpdates( LocationManager.GPS_PROVIDER(指定GPS定位的提供者),1000(时间间隔ms),1(为之间隔m),

                                                     new LoctionListenner(){@Override}(不需要重写方法,监听GPS定位信息是否改变);还需要权限检查的代码可由系统自动生成。

Location location=locationmanager.getLastKnowLocation(LocationManager.GPS_PROVIDER);

location.getLongitude()获取经度,location.getLatitude()获取纬度。

原文地址:https://www.cnblogs.com/fengchuiguobanxia/p/14369751.html