How to make HasTile work

I’ve successfully made a function so that if you click anywhere on the screen, a specific game object is created, but currently the game object can also be instantiated inside of the terrain. I tried saying “check if there’s a tile where the mouse is” using HasTile, but it always returns false, as if the entire tile map is empty. What’s going on? Here’s the code of the if statement. Not all of it is relevant to the question, mostly just the “if (!tm.HasTile (newPos))” (tm is the name of my tilemap).

         if (Input.GetMouseButtonDown (0)) {
             m_pos = Input.mousePosition;
             m_pos.z = 10;
             m_pos = Camera.main.ScreenToWorldPoint (m_pos);
             Vector3Int newPos = Vector3Int.RoundToInt (m_pos);
             if (!tm.HasTile (newPos)) {
                 Debug.Log ("there's nothing here");
                 GameObject rampi = Instantiate (object_ramp, m_pos, transform.rotation);
                 rampi.transform.name = "ramp" + ramp_i.ToString ();
                 rampi.transform.SetParent (canvas.transform);
                 ramp_i += 1;
             } else {
                 Debug.Log ("there's something here");
             }
             ramp.ready_to_place = false;
             ramp.carrying = false;
             can_place_ramp = false;
         }

Have you tried:

Vector3Int cellPosition = tilemap.WorldToCell(newPos)