2014-07-16 101 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 –