Я пытаюсь создать код, который начинает уведомление, когда пользователь приближается к местоположению. Я googled относительно темы, но не смог найти решение. Я использую следующий код, но он не работает.генерировать уведомление рядом с местоположением
Код ниже мой Location класса, внутренний класс MyLocationListener который реализует LocationListener
`@Override общественных недействительный onLocationChanged (Location LOC)
{
CharSequence от = "AlarmManager - Время вверх" ;
CharSequence message = "Это ваше предупреждение";
loc.getLatitude();
loc.getLongitude();
String Text = "My current location is: " +
"Latitud = " + loc.getLatitude() +
"Longitud = " + loc.getLongitude();
float radius = 500; //Distance in meters
Location location1 = new Location("GPS");
location1.setLatitude(loc.getLatitude());
location1.setLongitude(location1.getLongitude());
Location location2 = new Location("GPS");
location2.setLatitude(22.727739);
location2.setLongitude(75.886074);
Float distance = location1.distanceTo(location2);
distance = Math.abs(distance);
if(distance < radius)
{
Log.d("sdsd", "task location");
notMan = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification n = new Notification(R.drawable.ic_launcher, "Click here for details", System.currentTimeMillis());
Intent notificationIntent = new Intent(Location_Gps.this,Location_Gps.class);
PendingIntent pendingIntent = PendingIntent.getActivity(Location_Gps.this, 0, notificationIntent, 0);
n.setLatestEventInfo(Location_Gps.this, from,message, pendingIntent);
notMan.notify(10001, n);
}
Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
}
Любая помощь по этой теме оценивается.
ли это выполняется внутри службы? –
нет не работает внутри сервис – Shubhanshu