jQueryUI has the Position utility if you are already using that Javascript library
http://jqueryui.com/demos/position/ The demo is a little different as in odd, they are positioning 2 boxes relative another based on the user moving one of them so I had to unwind from that a bit to get something that worked for me. If you are dropping a pin on a map then look at the Draggable interaction for picking up the event.

