草庐IT

OnLocationChanged

全部标签

java - 如何在应用程序关闭时运行 onLocationChanged 方法(使用 onStop 方法)

我有这个方法,它管理我的位置:@OverridepublicvoidonLocationChanged(finalLocationlocation){if(inRun){ClocationmyLocation=newClocation(location,this.useMetricUnits());this.updateSpeed(myLocation);this.updateDistance(myLocation);this.updateAverageSpeed(this.distance,this.chronometer);if(activity.getText().toStrin

android - 即使我坐在同一个地方,也会调用 onlocationChanged

我使用了下面的代码并且一切正常,除了调用onLocationChanged,即使我坐在同一个位置。我认为它应该只在我移动时调用,对吗?我只想在移动一定距离后获取位置。请帮帮我。提前致谢。@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);locationMgr=(LocationManager)getSystemService(Context.LOCATION_SERVICE);locationMgr.

android - LocationListener 适用于模拟器,不适用于手机

我无法让LocationListener在我的手机上调用onLocationChanged()回调。当我在模拟器中运行我的代码时,它工作正常,每次我进行地理定位时都会调用回调。当我在手机上运行该应用程序时,什么也没有发生。永远不会调用回调。我的设置中同时启用了GPS和无线定位。该应用程序具有位置权限的所有使用权限。此外,当我在LocationManager对象上调用getLastKnownLocation()时,我的应用程序崩溃了。(仍然,只在我愚蠢的手机上)。即使我试图捕获导致它崩溃的异常,它仍然只是崩溃,所以我什至无法获得有关导致它崩溃的原因的任何信息。这非常令人沮丧。Locati

android - onLocationChanged 尚未被调用

我一直在尝试创建一个与map相关的android应用程序,但我意识到我的应用程序的onLocationChanged尚未被调用,因此map始终停留在默认区域(美国)。我的代码:publicclassMapMainActivityextendsMapActivityimplementsOnClickListener,LocationListener{MapViewmapView;/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCre

java - 如何获取当前的 GPS 位置?

我知道之前有人问过这个问题,但所有可用的解决方案都要求我使用onLocationChanged()方法,这样我就可以使用getLatitude()和getLongitude()方法获取坐标。但是onLocationChanged()会在我的设备位置发生变化时被调用。因此,为了获得我当前的位置,我必须移动我的设备。但我想在不移动设备的情况下获取当前坐标。我还在某处读到,我可以手动调用onLocationChanged()方法,我可以再次获取最后一个已知位置。最后一个已知位置有没有可能不是我当前的位置?还是可以使用最后已知的位置解决方案?这是我用来实现LocationListener的类的

android - onLocationChanged 只调用一次,不刷新

出于某种原因,我制作了一个小型gps应用程序onLocationChanged不刷新,它只在应用程序启动时运行一次。这是我的代码:publicBackgroundLocationService(){super("myintentservice");locManager=(LocationManager)context.getSystemService(Context.LOCATION_SERVICE);Criteriacrt=newCriteria();crt.setAccuracy(Criteria.ACCURACY_FINE);StringbestProvider=locManag

android - setTestProviderLocation() 不会触发调用 onLocationChanged()

我正在尝试让这段代码工作:TestingGPSinAndroid问题是,当我运行测试时,永远不会调用onLocationChanged():publicclassLocationTest0extendsAndroidTestCaseimplementsLocationListener{privateLocationreceived=null;publicvoidtestExample(){LocationManagerlm=(LocationManager)this.getContext().getSystemService(Context.LOCATION_SERVICE);Stri

android - 调用 getSystemService(Context.LOCATION_SERVICE) 和 onLocationChanged 时未调用 NullpointerException

我正在尝试创建更新当前GPS位置的后台服务。我在LocationManagerlm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);行收到一个NullPointerExceptionHomeActivity启动服务startService(newIntent(getApplicationContext(),ForHire.class));Service(ForHire)创建一个TimerTaskUpdatespublicclassForHireextendsService{...privateTimergetUpd

android - MockLocation testProvider 不调用 onLocationChanged

我的目标是GoogleAPI2.3.3并且有以下测试类importandroid.content.Context;importandroid.location.Criteria;importandroid.location.Location;importandroid.location.LocationListener;importandroid.location.LocationManager;importandroid.location.LocationProvider;importandroid.os.Bundle;importandroid.provider.Settings;

java - LocationClient requestUpdates onLocationChanged 从未调用过

我有这段代码可以用来定位map应用程序。我在GalaxyS2设备上测试它并且工作正常,但是当我在nexus4设备上测试它时,永远不会调用onLocationChanged回调。我可能做错了什么?这是我的Activity代码:publicclassBaseMapActivityextendsFragmentActivityimplementsInjectable,GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener,LocationListener{