Sensor Fun: Location Based Services and GPS for Android

The Android SDK offers a nice API to receive information about available providers for location based services and get the current location and coordinates. In this short tutorial we’re going to build a small activity that displays a list of available location providers and shows the current position using GPS services. Example Application Create a new Android Project using ADT and your IDE with a package named com.hascode.android.location_app Add the permissions needed to the AndroidManifest.xml – it should look like this <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hascode.android.location_app" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".LocationActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="7" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission> </manifest> ...

May 30, 2010 · 4 min · 731 words · Micha Kops