Convert from latitude, longitude to x, y

后端 未结 5 1815
夕颜
夕颜 2020-11-30 05:10

I want to convert GPS location (latitude, longitude) into x,y coordinates. I found many links about this topic and applied it, but it doesn\'t give me the correct answer!

5条回答
  •  不知归路
    2020-11-30 05:15

    Since this page shows up on top of google while i searched for this same problem, I would like to provide a more practical answers. The answer by MVG is correct but rather theoratical.

    I have made a track plotting app for the fitbit ionic in javascript. The code below is how I tackled the problem.

    //LOCATION PROVIDER
    index.js
    var gpsFix = false;
    var circumferenceAtLat = 0;
    function locationSuccess(pos){
      if(!gpsFix){
        gpsFix = true;
        circumferenceAtLat = Math.cos(pos.coords.latitude*0.01745329251)*111305;
      }
      pos.x:Math.round(pos.coords.longitude*circumferenceAtLat),
      pos.y:Math.round(pos.coords.latitude*110919), 
      plotTrack(pos);
    }
    

    plotting.js

    plotTrack(position){
    
    let x = Math.round((this.segments[i].start.x - this.bounds.minX)*this.scale);
    let y = Math.round(this.bounds.maxY - this.segments[i].start.y)*this.scale; //heights needs to be inverted
    
    //redraw?
    let redraw = false;
    
    //x or y bounds?
     if(position.x>this.bounds.maxX){
       this.bounds.maxX = (position.x-this.bounds.minX)*1.1+this.bounds.minX; //increase by 10%
       redraw = true;
     }
     if(position.xthis.bounds.maxY){
       this.bounds.maxY = (position.y-this.bounds.minY)*1.1+this.bounds.minY; //increase by 10%
        redraw = true;
     }
     if(position.y

提交回复
热议问题