• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Proximity and Current Location

H0lly

Lurker
Nov 25, 2009
2
0
Having a problem trying to get a proximity alert working where I want a marker to appear for the current location but only within a proximity radius.

When I enter co-ordinates either via DDMS or Geo Fix the lat/long being passed from the PendingIntent to the BroadcastReceiver doesn't match.

Code extracts:

Within onCreate:
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

locationListener = new MyLocationListener();

lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
1,
locationListener);

Location myloc = lm.getLastKnownLocation
(LocationManager.GPS_PROVIDER);
if (myloc != null) {
myloc.getLatitude();
myloc.getLongitude();
}

Intent intent = new Intent(PROXIMITY_ALERT);
Bundle bun = new Bundle();
bun.putDouble("myLatt", myloc.getLatitude());
bun.putDouble("myLongg",myloc.getLongitude());
intent.putExtras(bun);

PendingIntent proximityIntent =
PendingIntent.getBroadcast(edinmapActivity.this,-1, intent, 0);
lm.addProximityAlert(55.951002, -3.202085,
5000f, -1, proximityIntent);
//the returned value "check" is always null.* I know the new object
//ProxmityIntentReceiver object is being created.
Intent check = registerReceiver(new ProximityIntentReceiver(),
proximitylocationIntentFilter);

BroadcastReceiver:
public void onReceive (Context context, Intent intent) {
String key = LocationManager.KEY_PROXIMITY_ENTERING;
Boolean entering = intent.getBooleanExtra(key, false);

Bundle b = intent.getExtras();
final double mylat = b.getDouble("myLatt",0);
final double mylong = b.getDouble("myLongg",0);
.....
}

Inside my Activity in Manifest:

<intent-filter>
<action android:name="<package name>.action.PROXIMITY_ALERT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones