Question

Hello Programming World,

I am using the Google Maps API v3 and I have a map overlay that I need specific coordinates from.

In the image, I've managed to convert the two pixel coordinate sets from the top left and bottom right into latitude and longitude coordinates manually. I've found these equalities:

Top Left:
(1px [x-axis], 1px [y-axis]) in pixels equals...
(-109.05005006119609° [Longitude], 41.00062580014626° [Latitude]) in latitude/longitude

Bottom Right:
(575px [x-axis], 423px [y-axis]) in pixels equals...
(-102.0423399657011° [Longitude], 36.99314427042206° [Latitude]) in latitude/longitude

However, my boss later decided that he'd rather have Google Maps draw this with Google's polyline drawing class (so I need every border angle that I drew in my overlay in latitude/longitude coordinates).

My question is, given these two sets of coordinates, is there some sort of equation or formula that I can use so that I can find the pixel coordinate (which I already have in an image map file) and convert it to a latitude/longitude coordinate.

Example: Point of interest at 132px x-axis and 10px y-axis = a° Longitude and b° Latitude Find a and b.

I appreciate the help, Llewgnolm

No correct solution

OTHER TIPS

I talked to a friend of mine and he answered my question, so I figured I'd post the results here for anyone who'd like to know.

What we did was create a system of linear equations:
Lat/Lng = Multiplier*Pixels+Constant (L=m*p+c)

We substituted the numbers that I found manually into two equations for the system, i.e. (for Longitude):
-109.05...=m*(1)+c and
-102.04...=m*575+c and solved both for m and c


Eventually, the numbers came out to be (for longitude):
m = 0.01220895749767
c = -109.06228374530811

We can then use our values for m and c to plug in any pixel value to this equation and find the Latitude/Longitude, i.e (from the example numbers listed above again, for Longitude):
L = 0.01220895749767(132) - 109.06228374530811
L (Longitude at 132px in the x-direction) = -107.45070135561566°

This finds the degree values based off of the images pixels down to the 14th decimal (more than enough). For latitude, I just made a different system of equations with the latitude-based numbers inside to find different m and c values. Hope this helps anyone who stumbles across a similar problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top