Converting longitude/latitude to X/Y coordinate

前端 未结 3 485
醉酒成梦
醉酒成梦 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条回答
  •  萌比男神i
    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);
    

提交回复
热议问题