Both of these conditions are caused by the eyeball not being the sphere that "nature" intended.
Myopia is caused by the eyeball being elongated so that the focused image falls short of the retina.
Hyperopia is caused by the opposite, the eyeball is "too short" and the image is focused beyond the retina.
Both conditions are genetic.