How to understand if the location is off the map

If I add a location to the map, how can I find out if this location is outside the area shown on the map?
all this to recenter the map on the location only when I am adding a location external to the displayed map and not every time I add a location (which produces a bad effect)