我想将其从字符串转换为 lat/lng 数组,以便我可以使用它来跟踪用户的移动。或者有没有使用 json?

i want to convert this to a lat/lng array from a string so that i can use it to track users movements. or is there anyway by using json?

这里是输入:

[lat/lng: (10.9011873,76.9026255),lat/lng: (10.9011873,76.9026255),lat/lng: (10.9011873,76.9026255),lat/lng: (10.9011873,76.9026255),lat/lng: (10.9011873,76.9026255),lat/lng: (10.9011873,76.9026255),lat/lng: (10.94011873,76.29026255),lat/lng: (12.9011873,86.9026255),lat/lng: (15.9011873,76.29026255),lat/lng: (10.90131873,26.9026255),lat/lng: (10.901187233,76.904226255)]

我正在获取此输入并上传到 Sqllite 数据库中。然后稍后检索它以跟踪用户.. 他是否走在正确的道路上。 我的数据库将整个数组作为字符串返回,我需要将其转换为 lat/lng 数组。

简单:

    String answer = "[lat/lng: (10.9011873,76.9026255),lat/lng: (10.9011873,76.9026255),lat/lng: (10.9011873,76.9026255),lat/lng: (10.9011873,76.9026255),lat/lng: (10.9011873,76.9026255),lat/lng: (10.9011873,76.9026255),lat/lng: (10.94011873,76.29026255),lat/lng: (12.9011873,86.9026255),lat/lng: (15.9011873,76.29026255),lat/lng: (10.90131873,26.9026255),lat/lng: (10.901187233,76.904226255)]";

       ArrayList<Location> arrayListLatLng;
      String answer = "";
     answer = answer.replace("lat/lng: (" , "");
     answer = answer.replace(")" , "");
    String[] arrayLatLng = answer.split(",");

       for(int i = 0 ; i <arrayLatLng.length ; i++ ){
        Location j = new Location(rendomName);
        j.setLatitude(arrayLatLng[i]);
        j.setLongitude(arrayLatLng[i+1]);
        arrayListLatLng.add(new Location(j))
            }

Location A  = arrayListLatLng.get(0);
//make some code here with the A

希望对您有所帮助:)