I’m trying to add a proximity alert in my application but with variable radius.
If I use radius value like this
float radius = 100f;
It works!
But I’m trying to do it this way:
private void setProximityAlert(String Title, double lat, double lon, float radius, final int id, int requestCode){
// Expiration is 10 Minutes (10mins * 60secs * 1000milliSecs)
long expiration = 600000;
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Intent intent = new Intent(PROXIMITY_INTENT_ACTION);
intent.putExtra("id", id);
intent.putExtra("Title", Title);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
locManager.addProximityAlert(lat, lon, radius, expiration, pendingIntent);
}
I’m setting the proximity alerts this way:
this.dh = new DataHelper(ShowMap.this);
List<Pontos> list = this.dh.selectAll();
int count = 0;
for(Pontos p : list){
markerPlaces.add(new OverlayItem(p.getName().toString(), Integer.toString(p.getId()), new GeoPoint(p.getLat(), p.getLng())));
setProximityAlert(p.getName().toString(), p.getLat(), p.getLng(), p.getRadius(), p.getId(), count);
count++;
}
Note: p.getRadius() returns int value…
My problem is that is I use radius = 100f; it works fine, so I think I need to convert to float the same way, like the integer value is 10 so the float will be 10f.
Thanks!
It should be absolutely fine. There’s an implicit conversion from
inttofloat, so ifp.getRadius()returnsint, that should be implicitly converted tofloat– which suggests the problem isn’t where you think it is.You’ve said it works if you use 100f, but that your actual data is 10. So maybe the problem is that the proximity alert is estimating the distance as something like 50?