object not in original position when release

I want to make an object that will go back to its original position after dragging it around. But when I release it, the object just went to the bottom left corner of the canvas. This is my code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;


public class needle2 : MonoBehaviour, IPointerDownHandler, IEndDragHandler, IDragHandler 
{
    private Vector3 startPos;
    public Button needles;
    public GameObject needleonhand;
    public Animator injection;
    public bool playing = false;
    void Start()
    {
        needleonhand.SetActive(false);
        needles.gameObject.SetActive(true);
    }
    public void OnDrag(PointerEventData eventData)
    {
        transform.position = Input.mousePosition;
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        gameObject.transform.position = startPos;
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        gameObject.transform.position = startPos;
    }

    private void OnTriggerEnter2D(Collider2D OnNeedleTouch )
    {
        if(OnNeedleTouch.gameObject.name == "patientcure")
        {
            needleonhand.SetActive(true);
            injection.Play("injection");
            playing = true;
            needles.gameObject.SetActive(false);
        }

      
    }


}

You don’t actually save the start position in the PointerDown event. You are just assigning your current position to whatever startPos is initialized to (maybe Vector2(0,0) which is why it snaps to bottom down when you end dragging.

So that :

 public void OnPointerDown(PointerEventData eventData)
 {
     gameObject.transform.position = startPos;
 }

should be

public void OnPointerDown(PointerEventData eventData)
  {
      startPos = gameObject.transform.position;
  }