ProximityAlert problem

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

ProximityAlert problem

Postby steven_d » Mon Jul 20, 2009 3:40 pm

Hi,
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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void setProximityAlert() { //will call every time the location changed
  2.  
  3.  
  4.  
  5.   double lati = lat[arrayindex];
  6.  
  7.   double lng = lon[arrayindex];
  8.  
  9.   float radius = 10000f; //meters
  10.  
  11.   long expiration = -1; //-1 für "not expire"
  12.  
  13.  
  14.  
  15.   Intent intent = new Intent(TREASURE_PROXIMITY_ALERT);
  16.  
  17.   proximityIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
  18.  
  19.   lm.addProximityAlert(lati, lng, radius, expiration,proximityIntent);
  20.  
  21.   IntentFilter filter = new IntentFilter(TREASURE_PROXIMITY_ALERT);
  22.  
  23.   registerReceiver(new ProximityIntentReceiver(), filter);
  24.  
  25. }
  26.  
  27.  
  28.  
  29. /** Proximity Alert Broadcast Receiver */
  30.  
  31. public class ProximityIntentReceiver extends BroadcastReceiver
  32.  
  33. {
  34.  
  35.   @Override
  36.  
  37.   public void onReceive (Context context, Intent intent) {
  38.  
  39.   String key = LocationManager.KEY_PROXIMITY_ENTERING;
  40.  
  41.   entering = intent.getBooleanExtra(key, false);
  42.  
  43.   Toast.makeText(NavTrack.this, "Treasure: " + entering, Toast.LENGTH_SHORT).show();
  44.  
  45.   if (entering)
  46.  
  47.       arrayindex++;
  48.  
  49.   //lm.removeProximityAlert(proximityIntent);
  50.  
  51.  }
  52.  
  53. }
  54.  
  55.  
Parsed in 0.035 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
steven_d
Junior Developer
Junior Developer
 
Posts: 12
Joined: Mon Jul 20, 2009 1:15 pm
Location: Germany

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 5 guests