2

我有麻烦。我无法在我的 HTC 上获得令人难以置信的位置。

这是我的清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.locationfinder"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

这是我的活动

public class MainActivity extends Activity {
 /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

   /* Use the LocationManager class to obtain GPS locations */
   LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
   LocationListener mlocListener = new MyLocationListener();
   mlocManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener);
   }

   /* Class My Location Listener */
   public class MyLocationListener implements LocationListener
   {
       @Override
       public void onLocationChanged(Location loc)
       {
           loc.getLatitude();
           loc.getLongitude();

           String Text = "My current location is: " +
                         "Latitude = " + loc.getLatitude() +
                         "Longitude = " + loc.getLongitude();

           Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
       }

       @Override
       public void onProviderDisabled(String provider)
       {
           Toast.makeText( getApplicationContext(), "WIFI Disabled", Toast.LENGTH_SHORT ).show();
       }

       @Override
       public void onProviderEnabled(String provider)
       {
           Toast.makeText( getApplicationContext(), "WIFI Enabled", Toast.LENGTH_SHORT).show();
       }

       @Override
       public void onStatusChanged(String provider, int status, Bundle extras)
       {
           Toast.makeText( getApplicationContext(), "snth", Toast.LENGTH_SHORT).show();
       }

   }/* End of Class MyLocationListener */

}

如果我LocationManager.GPS_PROVIDER改为选择LocationManager.NETWORK_PROVIDER并且 GPS 已关闭,则它当前会在“禁用 GPS”的情况下进行吐司。但是,如果我使用 LocationManager.NETWORK_PROVIDER,无论 WiFi 状态如何,都不会发生任何事情。

4

0 回答 0