Handling multiple geofences transition with common area

前端 未结 3 1776
失恋的感觉
失恋的感觉 2020-12-29 07:55

If I have these two geofences, after registering these geofences I should get notified when I\'m entering or exiting the circumference of these circles. However, I don\'t wa

3条回答
  •  伪装坚强ぢ
    2020-12-29 08:16

    very schematically:

    boolean isTransition1, isTransition2, isTransition, insideCircle1, insideCircle2, insideUnion, insideUnionPrev;
    
    if (isTransition1 | isTransition2) {
        insideCircle1 = (dist(currPosition, centerCircle1) < radius1);
        insideCircle2 = (dist(currPosition, centerCircle2) < radius2);
        insideUnionPrev = insideUnion;
        insideUnion = insideCircle1 | insideCircle;
        isTransition = (insideUnion != insideUnionPrev);
        if (isTransition & insideUnion) println("Moved into region");
        if (isTransition & !insideUnion) println("Moved out of region");
    }
    

提交回复
热议问题