Converting Longitude & Latitude to X Y on a map with Calibration points

后端 未结 7 1021
既然无缘
既然无缘 2020-11-29 01:25

If i have a jpeg map with size sizeX, sizeY

and some calibration points on the map (X, Y, Lon, Lat)

What would be the algorithm for calculating the correspon

相关标签:
7条回答
  • 2020-11-29 01:34

    There is plenty of information on the Internet about calculating the distance between two pairings of latitude and longitude. We're using those calculations on our public website and they are not trivial to understand/discuss (so I won't try to cover them here). That said, they are easy to implement.

    Once you have a function that returns distance, you should be able to caculate the width and height of the map in terms of distance between the corners.

    Then you can calculate the horizontal and vertical distance of your point from the top-left corner.

    Now you find out what ratio of the map's width is represented by the distance between the left side and your point, apply that ratio to the pixel width and you have the number of pixels between the left side and your point. Repeat for the y-axis.

    (Pixels from left side) = (total width in pixels) * ((geocode distance between left and your point) / (geocode distance between left side and right side))

    (Pixels from top) = (total height in pixels) * ((geocode distance between top and your point) / (geocode distance between top and bottom))

    EDIT: As you research this further you will note that some solutions will present more accurate results than others due to the fact that you are approximating distance between two points on a spherical surface and mapping that on a flat surface. The accuracy decreases as the distance increases. Best advice to you is to try it out first and see if it meets your needs.

    0 讨论(0)
  • 2020-11-29 01:38

    Here's what worked for me, without so much bs.

    int x =  (int) ((MAP_WIDTH/360.0) * (180 + lon));
    int y =  (int) ((MAP_HEIGHT/180.0) * (90 - lat));
    

    The lat,lon coordinates were given to me by Android devices. So they should be in the same standard used by all Google Earth/Map products.

    0 讨论(0)
  • 2020-11-29 01:38

    There are many different map projection schemes. You would have to know which one(s) are used by your maps.

    For more information about map projection algorithms and forward/reverse mapping check out this link. It provides the formulas for a number of common projections.

    0 讨论(0)
  • 2020-11-29 01:40

    If using the Equidistant Cylindrical Projection type map, here is what you need to do:

    1. Find the Latitude and longitude of your location tutorial here:
      http://lifehacker.com/267361/how-to-find-latitude-and-longitude
    2. Input that information into the following formulas:
      x = (total width of image in px) * (180 + latitude) / 360
      y = (total height of image in px) * (90 - longitude) / 180

      note: when using negative longitude of latitude make sure to add or subtract the negative number i.e. +(-92) or -(-35) which would actually be -92 and +35

    3. You now have your X and Y to plot on your image

      More information can be found about this formula and the map type here:
      http://www.progonos.com/furuti/MapProj/Dither/CartHow/HowER_W12/howER_W12.html#DeductionEquirectangular
    0 讨论(0)
  • 2020-11-29 01:48

    Just make this(for Mercator projection map):

    extension UIView
    {
        func addLocation(coordinate: CLLocationCoordinate2D)
        {
            // max MKMapPoint values
            let maxY = Double(267995781)
            let maxX = Double(268435456)
    
            let mapPoint = MKMapPointForCoordinate(coordinate)
    
            let normalizatePointX = CGFloat(mapPoint.x / maxX)
            let normalizatePointY = CGFloat(mapPoint.y / maxY)
    
            let pointView = UIView(frame: CGRectMake(0, 0, 5, 5))
            pointView.center = CGPointMake(normalizatePointX * frame.width, normalizatePointY * frame.height)
    
            pointView.backgroundColor = UIColor.blueColor()
    
            addSubview(pointView)
        }
    }
    

    My simple project for adding coordinate on UIView: https://github.com/Glechik/MapCoordinateDrawer

    0 讨论(0)
  • 2020-11-29 01:48

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    #point{font-face:Arial; font-size:18px; color:#FFFF00; width:12px; height:12px;text-shadow: 2px 2px #000000}
    #canvas {position: absolute; top: 0px; left: 0px; z-index: -2}
            html,
            body,
            #canvas {
                width: 100%;
                height: 100%;
                overflow: hidden;
                margin: 0
            }
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    <script>
    $(window).on("load resize",function(e){
    
    var w = $("#canvas").width();
    var h = $("#canvas").height();
    // New York, NY (https://maps.googleapis.com/maps/api/geocode/json?address=New%20York,%20NY)
                   var lat = 40.91525559999999;
                   var long = -73.70027209999999;
    
    
    var x =  ((w/360) * (180 + long)) - 9;
    var y =  ((h/180) * (90 - lat)) - 18;
    
    $("#text").text('X:'+x+', Y:'+y);
    $("#point").offset({ top: y, left: x });
    
    });
    </script>
    </head>
    <body>
    <div id="text"></div>
    <div id="point">▼</div>
    <img id="canvas" border="0" src="http://friday.westnet.com/~crywalt/dymaxion_2003/earthmap10k.reduced.jpg">
    
    </body>
    </html>

    0 讨论(0)
提交回复
热议问题