私のAndroidプロジェクトは、ロケーションベースのリマインダーを提供します。サービスでは、現在のロケーションからデータベース内のすべてのロケーションまでの距離を計算しています。距離が500m未満の場合は、ユーザーに通知されます。問題は、距離の計算と通知の送信がサービス内で行われているため、距離が500m未満の場合、同じ場所に対して通知が繰り返し送信されることです。最終的に、アプリは強制的に閉じる必要があります。サービスクラスのonLocationChangedメソッドは次のとおりです。
    public void onLocationChanged(Location location) {
    double lat = location.getLatitude(),lng = location.getLongitude(),dblat = 0,dblng=0;
    Location currentlocation = new Location("current Location");
    currentlocation.setLatitude(lat);
    currentlocation.setLongitude(lng);
    int NOTIFICATION_ID = 1;
    String ns = Context.NOTIFICATION_SERVICE;
     String title,date,today;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
        Calendar cal=Calendar.getInstance();
        today = String.valueOf(cal.get(Calendar.YEAR)) + "-"
                + String.valueOf(cal.get(Calendar.MONTH)) + "-"
                + String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
    SQLiteDatabase database = new SQLiteHelper(getApplicationContext()).getWritableDatabase();
    Cursor c = database.rawQuery("select title,reminderdate,latitude,longitude from Reminder where type=1", null);
    int icon = R.drawable.ic_launcher;
    if(c.getCount()>0)
    { //System.out.println("c not null");
    c.moveToFirst();
    while(!c.isAfterLast())
    {
        title=c.getString(0);
        date=c.getString(1);
        if(date.equals(today))
        {
        dblat=c.getDouble(2);
        dblng=c.getDouble(3);
        Location dblocation = new Location("db Location");
        dblocation.setLatitude(dblat);
        dblocation.setLongitude(dblng);
        Double distance = (double) currentlocation.distanceTo(dblocation);
    if(distance<500)
        //Toast.makeText(this, "distance " + distance, Toast.LENGTH_LONG).show();
      {    long when = System.currentTimeMillis();
          Notification notification = new Notification(icon,title, when);
          RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
          contentView.setImageViewResource(R.id.notification_image, R.drawable.ic_launcher);
          contentView.setTextViewText(R.id.notification_title, "My custom notification title");
          contentView.setTextViewText(R.id.notification_text, "My custom notification text");
          notification.contentView = contentView;
          Intent notificationIntent = new Intent(this, ShowReminder.class);
          notificationIntent.putExtra("title", title);
          PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
          notification.contentIntent = contentIntent;
          notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
          notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
          notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
          notification.defaults |= Notification.DEFAULT_SOUND; // Sound
          mNotificationManager.notify(NOTIFICATION_ID, notification);       
    }   }
        c.moveToNext();
    }}
    c.close();
    database.close();
}
特定の場所の近くにいるときに、通知が繰り返し届くのではなく、1回だけ届くようにするにはどうすればよいですか?どんな助けでも大歓迎です。どうもありがとう!