{"comment":{"url":"https://api.github.com/repos/moagrius/TileView/comments/17039498","html_url":"https://github.com/moagrius/TileView/commit/17e8394022bea94175caa9719f37f685e96aaea0#commitcomment-17039498","id":17039498,"user":{"login":"peterLaurence","id":15638794,"avatar_url":"https://avatars.githubusercontent.com/u/15638794?v=3","gravatar_id":"","url":"https://api.github.com/users/peterLaurence","html_url":"https://github.com/peterLaurence","followers_url":"https://api.github.com/users/peterLaurence/followers","following_url":"https://api.github.com/users/peterLaurence/following{/other_user}","gists_url":"https://api.github.com/users/peterLaurence/gists{/gist_id}","starred_url":"https://api.github.com/users/peterLaurence/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterLaurence/subscriptions","organizations_url":"https://api.github.com/users/peterLaurence/orgs","repos_url":"https://api.github.com/users/peterLaurence/repos","events_url":"https://api.github.com/users/peterLaurence/events{/privacy}","received_events_url":"https://api.github.com/users/peterLaurence/received_events","type":"User","site_admin":false},"position":80,"line":119,"path":"tileview/src/main/java/com/qozix/tileview/geom/CoordinateTranslater.java","commit_id":"17e8394022bea94175caa9719f37f685e96aaea0","created_at":"2016-04-10T10:55:18Z","updated_at":"2016-04-10T10:55:18Z","body":"Assuming `x` is the absolute coordinate at 100% scale (e.g the unscaled x coordinate for a given scale), this formula has a little mistake (unless i am wrong). I think it should be :\r\n```\r\nreturn mLeft + ( factor * ( mRight - mLeft ) );\r\n```\r\nthat is to say :\r\n```\r\nreturn mLeft + ( factor * mDiffX );\r\n```\r\n\r\nBut we are adding this method because we want to know the relative coordinates of something on the screen (most likely the relative coordinates of a touch event so we can add a marker). \r\nTo do that lets say we override `ZoomPanLayout.onLongPress ( MotionEvent event )`. The information we can get from a long press are `event.getX()` and `event.getY()` which represent the coordinates (in pixels) of the touch relative to the current view. Those information are not sufficient to define a point on a map. We also have to know the offsets of the screen, which depend of the scale. These offsets are :\r\n`TileView.getScrollX()` and `TileView.getScrollY()`\r\n\r\nThat said, i understand why the user in #288 had to modify my proposed methods : i think he first tried to directly use `realToRelativeX` with the value obtained by `event.getX()`. That could not work and he manually add those offsets.\r\n\r\nTo sum up, to use `translateAbsoluteToRelativeX` from a touch event, we have to something like that :\r\n```\r\n@Override\r\npublic void onLongPress ( MotionEvent event ) {\r\n  /* get relative X */\r\n  int offsetX = getScrollX();\r\n  int absoluteScaledX = offsetX + event.getX();\r\n  int unscaledX = FloatMathHelper.unscale( absoluteScaledX, getScale() )\r\n  double relativeX = getCoordinateTranslater().translateAbsoluteToRelativeX( unscaledX );\r\n\r\n  /* get relative Y */\r\n  ...\r\n}\r\n```\r\n\r\nThat may not be obvious for all developer and maybe we should add a facility method that would return the relative coordinate from a x absolute pixel value obtained from a touch event."}}