Convert Lat/Longs to X/Y Co-ordinates

后端 未结 3 1626

I have the Lat/Long value of New York City, NY; 40.7560540,-73.9869510 and a flat image of the earth, 1000px × 446px.

I would like to be able to convert, using Javas

3条回答
  •  遥遥无期
    2020-11-30 22:35

    A basic conversion function in js would be:

    MAP_WIDTH = 1000;
    MAP_HEIGHT = 446;
    
    function convert(lat, lon){
        var y = ((-1 * lat) + 90) * (MAP_HEIGHT / 180);
        var x = (lon + 180) * (MAP_WIDTH / 360);
        return {x:x,y:y};
    }
    

    This will return the number of pixels from upper left. This function assumes the following:

    1. That your image is properly aligned with the upper left corner (0,0) aligning with 90* North by 180* West.
    2. That your coords are signed with N being -, S being +, W being - and E being +

提交回复
热议问题