1. In addition to the preceding Java module code, you must modify the permissions in the androidmanifest. xml file:
In uses-permission, the Code is as follows:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="zfy.mygps" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <activity android:name=".Mygps" android:label="@string/app_name" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/></manifest>
2. If you want to run in the simulator, you also need the simulator to support GPS, which may not be enabled when you enable the simulator. The simulator's support for GPS is as follows:
In eclipse: Window ---> Android SDK and AVD manager. Open the simulator Management window. If there is an available simulator, open edit. If not, create a new simulator, for example:
In the window on the right of hardware, You can see whether GPS is supported. If not, click New on the right to bring up the following window:
Select the GPS support and exit.
In this way, the simulator supports GPS. You can use the simulator to test your program,
3. Use emulator control in eclipse to test positioning;
Window --> show View --> emulator control (if there is no emulator control in show view, it is in the other menu). If the simulator is not enabled, the emulator control is gray and cannot be edited, if the simulator is gray after it is enabled, restart eclipse (do not turn off the simulator)
Some information on the Internet said that GPS is supported only in android2.2 or below, and has passed tests in android2.2 and android2.3.