android位置管理器问题与gps

时间:2015-04-21 14:12:45

标签: java android gps location locationmanager

我正试图将一个模拟位置设置为苏格兰。我究竟做错了什么?我已经在oncreate()中声明了我的位置管理器。如何模拟和设置整个手机的坐标?

错误:

04-21 14:08:23.835  21449-21449/com.example.ankhit.saveme E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.IllegalArgumentException: Provider "gps" unknown
            at android.os.Parcel.readException(Parcel.java:1429)
            at android.os.Parcel.readException(Parcel.java:1379)
            at android.location.ILocationManager$Stub$Proxy.removeTestProvider(ILocationManager.java:956)
            at android.location.LocationManager.removeTestProvider(LocationManager.java:1194)
            at com.example.ankhit.saveme.UserLocation.setMockLocation(UserLocation.java:208)
            at com.example.ankhit.saveme.UserLocation.access$000(UserLocation.java:41)
            at com.example.ankhit.saveme.UserLocation$4.onClick(UserLocation.java:168)

我的方法:

private void setMockLocation() {
          mLocationManager.removeTestProvider(LocationManager.GPS_PROVIDER);
          mLocationManager.addTestProvider
                    (
                    LocationManager.GPS_PROVIDER,
                    "requiresNetwork" == "",
                    "requiresSatellite" == "",
                    "requiresCell" == "",
                    "hasMonetaryCost" == "",
                    "supportsAltitude" == "",
                    "supportsSpeed" == "",
                    "supportsBearing" == "",

                    android.location.Criteria.POWER_LOW,
                    android.location.Criteria.ACCURACY_FINE
                    );

            Location newLocation = new Location(LocationManager.GPS_PROVIDER);

            newLocation.setLatitude (51.4276462);
            newLocation.setLongitude(-0.5509257);

            newLocation.setAccuracy(500);

            mLocationManager.setTestProviderEnabled
                    (
                            LocationManager.GPS_PROVIDER,
                            true
                    );

            mLocationManager.setTestProviderStatus
                    (
                            LocationManager.GPS_PROVIDER,
                            LocationProvider.AVAILABLE,
                            null,
                            System.currentTimeMillis()
                    );

            mLocationManager.setTestProviderLocation
                    (
                            LocationManager.GPS_PROVIDER,
                            newLocation
                    );

}

0 个答案:

没有答案