Rolando
Rolando

Reputation: 62714

How to use javascript to find the middle point lat long of an image?

I have an jpg image of 500 x 400 pixels. I know that at the pixel: 20x20, it is of latitude longitude X. I also know that at a second pixel: 400x100 its of latitude loingitude Y. Given that, how can I find out what is the latitude+longitude of the center pixel of the image? I want to know this because I have a photo of a map of an area of those dimensions that I want to display on top of a google map.

Example: Say I have a 500x400 pixel photo of a map of a top down picture of a amusement park. I know Attraction 1 of the amusement park is located at (latitude,longitude) X I know Attraction 2 of the amusement park is located at (latitude,longitude) Y Since I know that... I want to know what the middle latitude longitude is in the center of the image. That way I can "approximately" draw it at the right spot on a google map.

Upvotes: 0

Views: 198

Answers (2)

IMTheNachoMan
IMTheNachoMan

Reputation: 5839

I assume this is the image you're working with and you want the coordinates on the 500x400 image of the center of the box box made by X and Y?

map

Your variables:

  • C = the center -- this is what you're looking to find
    • C_{x} = the X coordinate of C
    • C_{y} = the Y coordinate of C
  • X = the top left of the inner box
    • X_{x} = the X coordinate of X -- 20 in your case
    • X_{y} = the Y coordinate of X -- 20 in your case
  • Y = the bottom right of the inner box
    • Y_{x} = the X coordinate of Y -- 400 in your case
    • Y_{y} = the Y coordinate of Y -- 100 in your case

The solution:

  • C_{x}
  • C_{y}

Basically, for C_{x} and C_{y} you find the respective centers in the inner box and add the offset the inner box has to the parent box. Does that make sense?

Upvotes: 1

Brad
Brad

Reputation: 163612

This is not something linear. Unfortunately, you do not have enough information. You need to know the projection and datum of both and make some conversions.

See also: https://en.wikipedia.org/wiki/Map_projection

Upvotes: 0

Related Questions