Unfortunately, there are no hard and set rules that govern the meaning but there are certain patterns which would help in cases of unceratinty. There are a set of prepositions in German which can take both the accusative and the dative cases. A general rule is ACCUSATIVE for MOTION, and DATIVE for POSITION. Here, the context helps, should the verb involve motion, the object would take the accusative. For example - compare 'Ich fahre in die Stadt' and 'Ich wohne in der Stadt'. The former sees 'in' take the meaning of 'towards/in the direction of' rather than just 'in/position' in the latter. This works similarly for prepositions such as 'auf', 'neben' and 'hinter'.
Some prepostions however extend beyond this rule. Here, the context of the sentence it is used in will always be of assistance. For example, 'an' + dative not only refers to position, eg. an der Mauer, but also to time, eg. am Montag. 'Vor' + dative is also similar as it has a similar meaning to the English 'before', not only in terms of position of an object, but also the time phrase. 'Vor' also expresses a cause or a reason in German, eg. Vor Nebel war nichts zu sehen - Because of the fog, nothing could be seen. The context a preposition is used in will always assist you with finding the meaning.