Saturday 15 March 2014

android - Update location every 30 seconds using Network Location Provider? -


How many seconds are turned on at each location? I want to update the user's location every 30 seconds and I do not know how to do this.

PS: I am using a network location provider and not GPS. I know that GPS is more accurate, but I care about battery consumption and indoor places.

It is my method that she calls a fixed interval of each time (I do not know everything at all) .. TextView TV Long, TVLatty; Button btn gate; Personal Location Manager Location Manager; Private string provider; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); SetContentView (R.layout.activity_main); TVLong = (TextView) Find ViewById (R.id.tvLong); TvLati = (TextView) findViewById (R.id.tvLati); Find BTN gate = (button) VVBIID (RBTNZ); BtnGet.setOnClickListener (this); LocationManager = (LocationManager) getSystemService (event .LOCATION_SERVICE); Criterion Criteria = new criteria (); Provider = locationManager.getBestProvider (Criteria, Incorrect); Location location = locationManager.getLastKnownLocation (provider); // Start the location field if (location! = Null) {System.out.println ("provider" + provider + "has been selected."); OnLocationChanged (location); } Else {tvLati.setText ("location is not available"); TvLong.setText ("location is not available"); } LocationManager.requestLocationUpdates (LocationManager.NETWORK_PROVIDER, 1000, 0, this); // I do not know what it really is. } Location changed to public zero (location location) {lat = (location.getLatitude ()); Lng = (location.getLongitude ()); String Value Lati = "Latitude:" + Latitude; String value long = "longitude:" + lng; TvLati.setText (valueLati); TvLong.setText (valueLong); } itemprop = "text">

option 1

Since you do not need to call onLocationChanged , do not use requestLocationUpdates since the API is completely unreliable on custom Android phone (Samsung). Its better you use an AlarmManager and call getLastKnownLocation , and phone onLocationChanged yourself.

Also keep in mind that getLastKnowLocation is the car on the Samsung phone, so you need to update the trigger behind the scene before you return to a good location Can Expect APIs

Call it just getLastKnownLocation, before its a hack.

Note that this does nothing for your application, just runs with backend cache

  HomeScreen.getLocationManager () requestLocationUpdates (LocationManager. NETWORK_PROVIDER is a good  last known location .., 0, 0, new LocationListener () {@Override Public Zero onStatusChanged (string provider, integer status, bundle extras) {} @Override Public Zero onProviderEnabled (string provider) { } @Override Public Zero onProviderDisabled (string provider) {} @ changed to location Public spaces override (final location location) {}});   

Option 2

Use all junk, and the new LocationClient API. It also has an API with an available location space, you can use it with alarm manager. With LocationClient, you do not have to worry about the best providers, providers available, the choice of accuracy and sensors. The location client merges them all into one good API.

For alarm manager

I had to work after some pain. So goes here.

No comments:

Post a Comment