简体   繁体   English

分割特定字符串

[英]Splitting Specific Strings

I am making an app that requires the user to click on a location and then will be directed to the location via Google Maps.The locations are an array of JSON files. 我正在制作一个需要用户单击某个位置然后通过Google Maps定向到该位置的应用。这些位置是JSON文件数组。 This is what the list looks like when complied... 这是编译后列表的样子... 在此处输入图片说明

I have this code to split up my coordinates because the coordinates are backwards in the JSON file and they need to be flipped. 我有这段代码可以拆分坐标,因为坐标在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);
  };

My question is how do I get the above code to run for a location when it is clicked? 我的问题是,如何在单击某个位置时使上面的代码运行?

Here is a plunk to my code if you want to check it out... http://plnkr.co/edit/OZZRgiEcrLzreW3lrc5v?p=preview 如果您想查看一下,这是我的代码的一大不足... http://plnkr.co/edit/OZZRgiEcrLzreW3lrc5v?p=preview

Assuming that FormatCoords is global. 假设FormatCoords是全局的。

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

I figured it out. 我想到了。 You need to edit all the coordinates prior to clicking the location. 单击位置之前,需要编辑所有坐标。

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)

So when the app loads, it removes the Z coordinate and then flippes the X and Y. 因此,当应用加载时,它会删除Z坐标,然后翻转X和Y。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM