I have a problem with the proximityAlert function. I develop a
navigation software, which reads some gps data out of a gpx file.
Then I write the first gps point in the addProximityAlert function.
When I am near this point, I want to raise an index to get the next
position from the gpx file (I save all positions in an array). But
sometimes the ProximityAlert fires one time, but sometimes it
fires 3 times or more? I think thats a problem with the expiration
time. I choose -1 (never expire). But if I use a value like 2000 (2
seconds), the alert fires only, if i reach the position in the next 2
seconds?
I have try to use the removeProximityAlert function (I have a global
PendingIntent variable therefore).
But then it fires 6 times instead of 3 times ?!
I have also test to use multiple PendingInten variables and add them
all with the addProximityAlert function. But then the ProximityAlert
of the third point can fire before the first or second point?!
Here is a part of my code:
Using java Syntax Highlighting
- private void setProximityAlert() { //will call every time the location changed
- double lati = lat[arrayindex];
- double lng = lon[arrayindex];
- float radius = 10000f; //meters
- long expiration = -1; //-1 für "not expire"
- Intent intent = new Intent(TREASURE_PROXIMITY_ALERT);
- proximityIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
- lm.addProximityAlert(lati, lng, radius, expiration,proximityIntent);
- IntentFilter filter = new IntentFilter(TREASURE_PROXIMITY_ALERT);
- registerReceiver(new ProximityIntentReceiver(), filter);
- }
- /** Proximity Alert Broadcast Receiver */
- public class ProximityIntentReceiver extends BroadcastReceiver
- {
- @Override
- public void onReceive (Context context, Intent intent) {
- String key = LocationManager.KEY_PROXIMITY_ENTERING;
- entering = intent.getBooleanExtra(key, false);
- Toast.makeText(NavTrack.this, "Treasure: " + entering, Toast.LENGTH_SHORT).show();
- if (entering)
- arrayindex++;
- //lm.removeProximityAlert(proximityIntent);
- }
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
Example gps-data in file:
lat, lon 3 3
lat, lon 10 10
The output via Toast and telnet consoloe:
1. geo fix 3 3: Treasure: true (1x)
2. geo fix 5 5: Treasure: false (1x)
3. geo fix 7 7: no output
4. geo fix 10 10: Treasure true (3x)
Thanks for help,
Stefan


