Q:

Gesture detection coordinates not synced with viewport

I am trying to implement pan(float x, float y, float deltaX, float deltaY) from GestureDetector  .
I set the coordinates of the texture to the parameters of the pan , so whenever i drag the texture
on screen it draws there . it worked perfectly .

Now i put a camera and a viewport in the screen and suddenly the the
  texture isn't following the drag coordinates properly .

here is the create() method where I initialise my camera and viewport
    @Override
public void create () {
    batch = new SpriteBatch();
    img = new Texture("badlogic.jpg");
    pos = new Vector2(0,0);

    camera = new OrthographicCamera();
    camera.position.set(width/2,height/2,0);
    viewport = new StretchViewport(width,height,camera);
    viewport.apply();
    gestureDetector = new GestureDetector(this);
    Gdx.input.setInputProcessor(gestureDetector);
}

and here is how i implement the pan method from the interface
@Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
    pos.x = x ;
    pos.y = Gdx.graphics.getHeight() - y ;
    return true;
}

The code works fine when i am touching the top left corner of the screen
where the Gesture detector considers the coordinate (0,0) but as I drift towards 
the right ,the texture drawn is somewhat ahead of the x coordinate being touched  . 
It is working fine with respect to the Y axis .

A:

I havent checked what you are trying to achieve but if you say it worked fine before you added a camera and viewport then it probably has something to do with screen vs world coordinates. 
I believe what you are looking for is viewport.unproject() or camera.unproject(), this will transform screen coordinates into world coordinates and it should work properly. 
Addition:

unproject(Vector3 screenCoords)
    Function to translate a point given in screen coordinates to world space.

source: Libgdx Camera Doc

