This is a question that comes into mind every now and then. I personally believe the robot is not required to know its location information because:
1) if they are programmed to wander around, they can easily avoid obstacles without the need to know where it is as long as the sonar sensor provides accurate measurements of the distance of an object that is directly in front of the robot.
2) the robot can make use of the SLAM technique and build up a map of its environment, for which they do not require any such information of their location.
... What would be a more justifiable explanation or answer to a question like this? I programmed a robot a long time ago and had it move to multiple locations and had given it obstacle avoidance behavior and it almost always got to the locations and returned without it knowing its own location information. I had made use of the sonar sensor (for obstacle avoidance) and had used a color sensor (to have it look for the red color placed on the ground, and so it performs the next move).
If the task is to wander only, no need of location and robot only needs obstacle avoidance behaviour. But in case you want robot to move to a specific location in a map, location and orientation information is necessary. SLAM stands for Simultaneous Localization and Mapping, meaning it is generating a map while also simultaneously localizing itself in that map. So localization information is a must for SLAM.
In a way the color sensor in your case is also giving info about location but in form of red or non-red area in an environment represented as red and non-red areas.