The short answer is, you can't, not without inaccuracies. That is because lat/lon is not a projection and is not cartesian. If your map is already Mercator (and you say it is), then you can use the following code --

my $h_img_dims => {img_width => 200, img_height => 200}; my $h_map_bbox => {map_minx => 2090491, map_miny => 482208, map_maxx + => 2224055, map_maxy => 587708}; my $h_new_center => {x => 200, y => 100}; # for pan right/East #my $h_new_center => {x => 0, y => 100}; # for pan left/West #my $h_new_center => {x => 100, y => 200}; # for pan bottom/South #my $h_new_center => {x => 100, y => 0}; # for pan up/North # Convert the mouse click to earth coordinates my ($x, $y) = _pixel2earth( h_img_dims => $h_img_dims, h_map_bbox => $h_map_bbox, h_new_center => $h_new_center, ); sub _pixel2earth { my (%args) = @_; my $h_img_dims = $args{h_img_dims}; my $h_map_bbox = $args{h_map_bbox}; my $h_new_center = $args{h_new_center}; # Mouse clicks equivalent in earth coordinates return ( $h_map_bbox->{map_minx} + ($h_new_center->{x} * ( ($h_map_bbox->{m +ap_maxx} - $h_map_bbox->{map_minx}) / $h_img_dims->{img_width} )), $h_map_bbox->{map_miny} + ($h_new_center->{y} * ( ($h_map_bbox->{m +ap_maxy} - $h_map_bbox->{map_miny}) / $h_img_dims->{img_height} )) ); }

If you want to display a rectangular image, but measure non-rect coordinates such as lat/lon, you will have to project on the fly. Look at Proj.4, or better yet, look at MapServer which can do the image generation for you as well.

--

when small people start casting long shadows, it is time to go to bed

In reply to Re: Converting Pixels to LatLong by punkish
in thread Converting Pixels to LatLong by BaldPenguin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.