This is not so complicated as you think.
The simplest way to interpret it is ,
when you put 里 after a place,it corresponds to "in" or "inside"
and if there is no 里,it's like "at".
another way to distinguish is 里 is more specific than no 里,
我在家吃晚饭。
我在家里吃晚饭。
mean the same thing,the subtle difference is than one is more like
"I will have dinner at home." and "I will have dinner inside my home".
with 里 it's more precise than without it.
Another example could be
我在学校。(you may be somewhere near the school ,not necessarily inside it)
我在学校里。(you are inside the campus)。
Maybe some customs are helpful to you.
1,With a facility inside a city(like a school ,a bus stop,a park ,a stadium and library...),it is correct either way.
so 图书馆 is correct either way ,though 我在图书馆里念书? is not used as often,but it's correct。
2,for cities,provinces,countries... we normally don't use 里 except in some special contexts.
so if you said 我在北京里,or 我在美国里,they would sound strange to us.
sorry if the wording is a bit sloppy since I improvised it.Hope this helps.