2014-07-16 102 views
0

我正在製作一個應用程序,要求用戶點擊某個位置,然後通過Google Map將其定向到該位置。位置是一組JSON文件。這是列表看起來像什麼時候編寫的... enter image description here分割特定字符串

我有這個代碼來拆分我的座標,因爲座標是在JSON文件中倒退,他們需要翻轉。

var FormatCoords = function(){ 
    CoordinateToString = location.Point.coordinates.toString() 
    SplitCord = CoordinateToString.split(",") 
    $scope.Lat = SplitCord[1]; 
    $scope.Lon = SplitCord[0]; 
    var FinalCord = Lat.concat(Lon); 
    }; 

我的問題是我如何獲得上述代碼運行的位置,當它被點擊?

這裏是一個普拉克我的代碼,如果你想看看... http://plnkr.co/edit/OZZRgiEcrLzreW3lrc5v?p=preview

回答

0

我想通了。在點擊位置之前,您需要編輯所有的座標。

location.Point.coordinates = location.Point.coordinates.substring(0, clength - 2).split(","); 
     Lat = location.Point.coordinates[0] 
     Lon = location.Point.coordinates[1] 
     Com = "," 
     location.Point.coordinates = Lon.concat(Com,Lat) 

所以當應用程序加載時,它消除了Z座標,然後flippes X和Y.

0

假設FormatCoords是全球性的。

$('a').on('click', function() { 
    FormatCoords(); 
}); 
+0

林真正困惑你的意思是實際的選擇是什麼。這裏是我的朋克的鏈接,如果你想看看它將不勝感激。 http://plnkr.co/edit/OZZRgiEcrLzreW3lrc5v?p=preview –