Get the position of an object inside a group after moving both.

I have 2 display groups. Each group has few display objects inside it. Each display object has unique (x,y) positions. Each group has unique (x,y) positions. Both groups have “anchoreChildren = true”

What I would like to do is when I click on an object from the first group is to move to a corresponding object from the second group. I use a “transition” and the “object:localToContent” method to get the (x,y) of the target object. 

What happens is the object moves “close” to the target but not at its exact position, there is always an offset.

I posted an answer to a similar problem here:

https://forums.coronalabs.com/topic/70000-dragging-a-sprite-between-display-groups/?p=364727

The short is that you want to convert positions using the display API functions.

This doesn’t work for me + I need the first object to remain a child of its parent.
My question simply is:
I need to get the position of object2 inside group 2 relative to object 1 that is inside group 1 and move object 1 there.
simple  “object2:localToContent” doesn’t work properly as I mentioned above. 

Then you are performing the wrong calculation…

For the two objects whose relative positions you want to calculate, you need to get them in the same zone of reference. The easiest way to do that is to convert both of their location values to content values and compare them. If you want to convert the location of one of them to content values and then convert to the parent group of the other object it will work, too.

So, in short, to get the location of object 2 relative to object 1, by converting object 2’s location to object 1’s parent group, you would do this:

local bx, by = objectB:localToContent(0,0) bx, by = groupA:contentToLocal(bx,by) local diffX, diffY = bx-ax, by-ay

I posted an answer to a similar problem here:

https://forums.coronalabs.com/topic/70000-dragging-a-sprite-between-display-groups/?p=364727

The short is that you want to convert positions using the display API functions.

This doesn’t work for me + I need the first object to remain a child of its parent.
My question simply is:
I need to get the position of object2 inside group 2 relative to object 1 that is inside group 1 and move object 1 there.
simple  “object2:localToContent” doesn’t work properly as I mentioned above. 

Then you are performing the wrong calculation…

For the two objects whose relative positions you want to calculate, you need to get them in the same zone of reference. The easiest way to do that is to convert both of their location values to content values and compare them. If you want to convert the location of one of them to content values and then convert to the parent group of the other object it will work, too.

So, in short, to get the location of object 2 relative to object 1, by converting object 2’s location to object 1’s parent group, you would do this:

local bx, by = objectB:localToContent(0,0) bx, by = groupA:contentToLocal(bx,by) local diffX, diffY = bx-ax, by-ay