2012-03-27 38 views
0

我問你,因爲我現在掙扎了幾天;我搜索了互聯網和計算器,但沒有找到任何東西。問題經緯度和長精度,取決於地點

我需要在地圖上非常精確地放置標記/圓圈/任何東西。 但是,我似乎只能將它們繪製在精確度取決於我所處位置的網格上。因此,他們的位置不夠準確。

我正在使用Wt(C++),但它似乎並不是問題的一部分。 我寫了代碼,繪製了一個20 * 20的圓陣列,其座標是等距的。無論我在巴黎還是在紐約,我都沒有得到同樣的結果。

在巴黎: (不能發佈圖片,因爲這是我的第一個問題) http://img818.imageshack.us/img818/7841/parism.png

在新紐約: http://img193.imageshack.us/img193/9822/newyorkq.png

在巴黎,我得到了經度精確度,但不緯度。 在紐約,我無法獲得緯度和經度的準確性。

這裏是我使用的代碼:

/*Choose between both*/ 
    double centerLat = 40.714468; double centerLng = -74.005966;//New-York 
    //double centerLat = 48.854607; double centerLng = 2.347126;//Paris 

    /*Other parameters*/ 
    double lngMargin = 0.000400; 
    double latMargin = 0.000400; 
    int granularity = 20; 

    int i,j; 
    WVBoxLayout* layout = new WVBoxLayout(); 
    WColor::WColor myBlue = WColor::WColor(0,0,255,255); 
    WColor::WColor myRed = WColor::WColor(255,0,0,255); 
    WColor::WColor myTransparent = WColor::WColor(0,0,0,0); 
    WGoogleMap::Coordinate coordArray[granularity][granularity]; 

    /* Creating and configuring the map */ 
    WGoogleMap *map = new WGoogleMap(WGoogleMap::Version3); 
    WGoogleMap::Coordinate centerCoord = WGoogleMap::Coordinate(centerLat,centerLng); 
    setLayout(layout); 
    resize(height,width); 
    map->setCenter(centerCoord,19); 
    map->setMapTypeControl(WGoogleMap::DefaultControl); 
    map->enableScrollWheelZoom(); 
    map->addCircle(centerCoord,2,myBlue,2,myTransparent); 

    /* Here is the loop that draws the circles */ 
    for(i=0 ; i<=granularity-1 ; i++){ 
      for(j=0 ; j<=granularity-1 ; j++){ 

        coordArray[i][j] = WGoogleMap::Coordinate(centerLat + beforeOrAfterTheCenter_Lat * (latMargin/granularity) * i, 
            centerLng + beforeOrAfterTheCenter_Lng * (lngMargin/granularity) * j); 

        map->addCircle(coordArray[i][j],1,myRed,2,myTransparent); 
      } 
    } 

的代碼應該工作正常。你有什麼線索可以做些什麼來獲得更高的準確性嗎?這是一個衆所周知的問題嗎?

非常感謝你的幫助,你可以提供,

L.

+0

我的猜測是,投影在經度,緯度,像素等方面不相等。試着繪製你的網格(Lat,lon)然後(-Lat,lon)來查看形狀是否相似或倒置。也許在赤道附近它工作? – 2012-03-27 16:44:46

+0

Heitor,你是對的。非常感謝你。在(0,0)附近,我有一個完美的網格,但是從這點來看,更糟糕的事情是。 我會嘗試找出mapCanvasProjectionObject的一個解決方案,並會保持發佈。你認爲它可以工作嗎?你會嘗試別的嗎? – Luke 2012-03-28 07:52:38

+0

我相信有投影等於經緯度和長度。距離顯得同樣遙遠。不過,我認爲將Google地圖投影中的LatLngs等值投影轉換爲新的LatLngs會比較棘手。那裏可能有公式。我不知道有什麼方法可以更改Google地圖中的投影。 – 2012-03-28 13:45:58

回答

2

掙扎的幾個小時後,我終於發現了什麼問題了。

我使用重量(C++),但它似乎並不成爲問題

那麼的一部分,它實際上是。 Wt使用std :: stringstream生成JavaScript代碼,並且當您給他一個double時,此對象不具有默認無限精度:它只需要6位數字。這意味着如果你在該點之前有一個數字,那麼你之後有5個數字,並且如果你在該點之前有兩個數字,那麼你之後有4個數字。 這就是爲什麼我們在巴黎經度精度很高的原因,但不是緯度(lng是6,lat是45)。這就是爲什麼紐約的經度和緯度精度都很差(兩點都在點之前)

爲了解決這個問題,我只是用自定義方法重載了addCircle(以及addMarker和所有其他函數)函數,我設置std :: stringstream的精度與 std :: stringstream :: precision(int n) 方法一起使用,我還不知道。

我在報告重新報道此問題,它可能會很快糾正。

Heitor,muito obrigado pela ajuda。

再見,