Well, lets see. A latitude/longitude coordinate is in degrees, minutes, seconds (with decimal). 60 seconds to a minute, 60 minutes to a degree. So, first, convert your two longitudes to "absolute" numbers (i.e. (degrees * 3600) + (minutes * 60) + secs) and get the difference between the two (i.e. the higher - the lower). Now, divide this by the pixel width of the image, save these three numbers (the left, right, and interval). Now, do the same with the lattitudes and the height.
Now, when someone clicks on the map get that coordinate in pixels. Multiply the "x" by the width interval and the y be the height interval (if you want the coordinate from the "center" of the pixel, rather than the upper left corner of the pixel than add half the interval to each). Now add the "x" result to the "left" number (or subtract it if the left number was the larger). Do the same with the "y" result and the "top" number.
Now, (number / 3600) rounded down is the degrees, ((number % 3600) / 60) rounded down is the minutes, this ((number % 3600) % 60) are the seconds.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
You need to scale the pixels to the number of degrees covered by the map.
You need the lat/long of the upper left corner and for the lower right corner.
Given those, you can convert any mouse click's x,y to a lat/long.
There may be some trigonometry required at higher latitudes because of the converging of the longitude lines as you go north.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
masijade gave you clear formula how to convert an entry of 12degrees 34minutes 56sec down to seconds value that you can then apply to your image calculations.
Your formula "degrees + (minutes * 60) + (secs*3600)" is completely wrong. Can you explain what are you trying to calculate out of it?
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
decimalVal = (d*3600) + (m*60) + s;
not
decimalVal = (d*3600) + (m/60) + s;
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
Well madawa123 has problems to reference properly as he asked about
degrees + (minutes * 60) + (secs*3600)
and page says
degrees + (minutes/60) + (seconds/3600) (difficult to see, but it uses divide "back slash" instead of times "*")
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
You need to give lat/long values for the corners of the map area to be able to determine the x,y pixel values for a given lat/long.
Are the lat/long positions like this: 12.23456 degrees North 89.44323 degrees West?
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
Are the lat/long in degrees, minutes and seconds?
Did you convert them to decimal degrees by doing: degrees + min/60 + sec/3600
Then "normalize" the values to map to 0,0 to 800,500
Subtract the min degress from the max degress and divide by the pixel length for that direction.
Also you need to consider what latitude you are at. The longitude lines come together as you go North/South.
This will depend on whether you are North or South and East or West.
Best to use a piece of paper for each of the 4 cases (NE, NW, SE, SW) and write the lat/long for the upper left corner which will be 0,0 in pixels and the lower right corner: 800, 500
There will be distortion if the drawing map area does not have the same proportions as the lat/long ranges.
Is Your chart is over western Melbourne
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
a formula to give the answer for pixel
Subtract and divide.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
Use a piece of paper to map out the pixels vs the lat/long.
The upper left corner is 0,0 in pixels and the North West corner in lat/long.
The distance from the left side to the right side is the max deg long minus the min deg long adjusted for latitude. Divide that by the width in pixels.
This is very simple math.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656