先設定存取權限

在Androidmanifest.xml設定許可權

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

取得程式如下

public static void showGPS(CoNtext ctx) {
LocationManager lms = (LocationManager) ctx.getSystemService(ctx.LOCATION_SERVICE);
Location location = lms.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Double longitude = location.getLongitude();
Double latitude = location.getLatitude();
Toast.makeText(this, "Lo = " + longitude + "; La = " + latitude ,Toast.LENGTH_SHORT).show();
}
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()