Imagine 9 pieces of grid paper placed in a 3x3 grid. Each piece of paper is a grid 300x400. Each piece of paper is actually a tilemap and they are all pinned to the center tilemap. If you drag the center tilemap off the screen there is a duplicate copy of the center tilemap (an "edge" tilemap) that is now on the screen (this makes for a continuously moveable map). On a touch end where you are not touching the center tilemap, the center tilemap is placed at the last touched "edge" tilemap location (the 8 "edge" tilemaps are still pinned and shift accordingly. This way you can scroll again and it will look seamless until you happen upon an "edge" tilemap.
The problem, each tilemap is labelled 0-300x,0-400y. When the map shifts the tilemap.positiontotileX,Y shifts as well. Which means on one click the distance formula works, but on the next click it shifts and gives the inverse.
I have no idea if any of this makes sense, but it's a huge pain.
The only other solution I can think to use would be to pin small sprites to the map used for starting distance and then just use a distance(pin.x,pin.y,touch.x,touch.y) {divided by the actual tile size). It should work, but seems inefficient.