与Android类似,直接贴代码~
1 LocationManager lm = (LocationManager) this.getSystemService(LOCATION_SERVICE); 2 Location location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 3 double jingdu = location.getLatitude(); 4 double weidu = location.getLongitude(); 5 double haiba = location.getAltitude(); 6 System.out.println("经度=" + jingdu + " 纬度=" + weidu + " 海拔=" + haiba);
最后添加权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>