I was wondering about how some websites know the location of IP addresses we query them to resolve for it's location.
Then I remembered the IANA assigns IP addresses to different Regional Internet Registrars (RIR) like AFRINIC, APNIC, ARIN, LACNIC, RIPE NCC (as mentioned here https://www.iana.org/numbers) which are further subdivided to different National Internet Registries (NIR) like CNNIC, APJII, JPNIC, KRNIC, etc. for every region under RIR
I looked up to understand which IP ranges are provided to which RIR and further down the tree but didn't quite understand what they've written here in this link originated from the same page mentioned above.
Maybe I'm wrong but I think there is a hierarchy of IP range allocation with regards to their location otherwise how'd these online services know the location of that IP address. (Also not to forget, collaboration of multiple databases helps obviously)
I want to basically guess the location of an IP address based on some pattern associated with the way the IANA has done IP allocation to different RIR.
Can I guess the Geolocation of an IP simply based on it's pattern for both IPv4 and IPv6?
Please correct me if I am missing anything or am wrong in any concept.
EDIT: The answer posted by Steffen Ullrich does not touch on the concept of links between IP range allocation with regards to their location as is asked in this question but the link provided is also helpful to understand other things