Converting longitude/latitude to X/Y coordinate

前端 未结 3 456
醉酒成梦
醉酒成梦 2020-11-28 19:38

I created a map using Google Maps API that highlights all Minnesota counties. Basically, I created the county polygons using a set of longitudes/latitudes coordinates. Here\

相关标签:
3条回答
  • 2020-11-28 20:09

    The big issue with plotting maps is that the spherical surface of the Earth cannot be conveniently converted into a flat representation. There are a bunch of different projections that attempt to resolve this.

    Mercator is one of the simplest: it assumes that lines of equal latitude are parallel horizontals, while lines of equal longitude are parallel verticals. This is valid for latitude (1 degree of latitude approximately equals 111 km no matter where you are), but not valid for longitude (the surface distance of a degree of longitude is proportional to the cosine of the latitutude).

    However, as long as you're below about 45 degrees (which most of Minnesota is), a Mercator projection works very well, and creates the forms that most people will recognize from their grade school maps. And it's very simple: just treat the points as absolute coordinates, and scale to whatever space you're drawing them in. No trig necessary.

    0 讨论(0)
  • 2020-11-28 20:21

    Remember that how a map looks is a function of the projection used to render the map. Google Maps appears to use a Mercator projection (or something very similar to it). What projection does your algorithm equate to? If you want your 2D representation to look just like Google's you need to use an identical projection.

    0 讨论(0)
  • 2020-11-28 20:30

    To convert lat/lon/alt (lat in degrees North, lon in degrees East, alt in meters) to earth centered fixed coordinates (x,y,z), do the following:

    double Re = 6378137;
    double Rp = 6356752.31424518;
    
    double latrad = lat/180.0*Math.PI;
    double lonrad = lon/180.0*Math.PI;
    
    double coslat = Math.cos(latrad);
    double sinlat = Math.sin(latrad);
    double coslon = Math.cos(lonrad);
    double sinlon = Math.sin(lonrad);
    
    double term1 = (Re*Re*coslat)/
      Math.sqrt(Re*Re*coslat*coslat + Rp*Rp*sinlat*sinlat);
    
    double term2 = alt*coslat + term1;
    
    double x=coslon*term2;
    double y=sinlon*term2;
    double z = alt*sinlat + (Rp*Rp*sinlat)/
      Math.sqrt(Re*Re*coslat*coslat + Rp*Rp*sinlat*sinlat);
    
    0 讨论(0)
提交回复
热议问题