Skip to content

Calculation not correct? #4

@JoepS

Description

@JoepS

The conversion from degrees to pixels is working just fine, but if i try to convert the pixels back to degrees again it is off
example:
lat = 36.1
lng = -5.4
degtopx ->
x = (lon + 180) * (mapW / 360);
y = (mapH /2)-(mapH *Mathf.Log(Mathf.Tan((Mathf.PI/4)+((lat Mathf.PI/180)/2)))/(2Mathf.PI));
(mapH & mapW are both 2048)
results in (993.56, 803.25)

and this back to degrees
pxtodeg ->
lat = (x - (mapW / 2)) / (mapW / 360);
lng = (Mathf.Exp(-(y-(mapH /2)) /mapH (2Mathf.PI))- Mathf.Tan((Mathf.PI/4))*2)/(Mathf.PI/180);
results in (-1.8, -5.4)

so the latitude is way off?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions