I am trying to map the latitude and longitudes of earthquakes on a world map, similar to this video - https://www.youtube.com/watch?v=ZiYdOwOrGyc and i'm trying to implement it in Python Tkinter instead of in JS. The problem occurs when i attempt to convert the latitude and longitude to x and y coordinates on a tkinter canvas. I was using the formulae from the web mercator wiki page https://en.wikipedia.org/wiki/Web_Mercator_projection and i haven't had any luck, it either places it too far, or off the map entirely.
According to the formulae on web mercator, i've tried to resize my world map image to specific width and height from (2000, 1546) to (1024, 512) or (512, 512) to see if that did anything, but it places the point too far or somewhere else entirely. After that i tried seeing had i converted lat/long degrees to radians for the formulae among other things, but its safe it say i'm not at all good at math so this is beyond me.
This is the class for a circle that would be put on world map and it includes methods for converting lat and long to x and y:
class MyOval(object):
def __init__(self, lat, long):
#self.lat=math.radians(lat)
#self.long=math.radians(long)
self.lat=lat
self.long=long
self.x=None
self.y=None
self.oval_obj = None
def mercX(self, long):
long = math.radians(long)
a = ((256)/(2*math.pi)) * pow(2, 1)
b = long + math.pi
return a*b
def mercY(self, lat):
lat = math.radians(lat)
a = ((256)/(2*math.pi)) * pow(2, 1)
b = math.tan((math.pi/4) + (lat/2))
c = math.pi - math.log(b)
return a*c
def redraw_coords(self):
self.x = self.mercX(self.long)
self.y = self.mercY(self.lat)
to zoom around and scroll the map i used the python tkinter code for that from here: Tkinter canvas zoom + move/pan
As an example I used the lat/long coords of (33.863, -117.4973333), which is a place in California and when i run my program it places it all the way up north near Alaska. Screenshot of google maps vs my placement: https://ibb.co/J77gwn4
EDIT: Here is a link to my full code + the world map image all in zip: https://ufile.io/5b50flpa