请帮忙随机生成些格式与{"date":"10:48:00","location":"120.781084,30.738425","pos":"中国浙江省嘉兴市南湖区富润路257号"}一致的定位坐标数据,从00:00:00开始每隔10分钟一个坐标点,到23:59:59结束,请给我Java实现代码
时间: 2023-07-02 07:18:26 浏览: 104
好的,以下是生成坐标数据的 Java 代码:
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class LocationGenerator {
public static void main(String[] args) {
String[] locations = {
"120.781084,30.738425",
"120.788344,30.746836",
"120.795605,30.755247",
"120.802865,30.763658",
"120.810126,30.772069",
"120.817386,30.780480",
"120.824647,30.788891",
"120.831907,30.797302",
"120.839168,30.805713",
"120.846428,30.814124",
"120.853689,30.822535",
"120.860949,30.830946",
"120.868210,30.839357",
"120.875470,30.847768",
"120.882731,30.856179",
"120.889991,30.864590",
"120.897252,30.873001",
"120.904512,30.881412",
"120.911773,30.889823",
"120.919033,30.898234",
"120.926294,30.906645",
"120.933554,30.915056",
"120.940815,30.923467",
"120.948075,30.931878",
"120.955336,30.940289",
"120.962596,30.948700",
"120.969857,30.957111",
"120.977117,30.965522",
"120.984378,30.973933",
"120.991638,30.982344",
"120.998899,30.990755",
"121.006159,30.999166"
};
Random random = new Random();
List<String> positions = new ArrayList<>();
// 从 00:00:00 开始,每隔 10 分钟生成一个坐标点,直到 23:59:59
for (int hour = 0; hour < 24; hour++) {
for (int minute = 0; minute < 60; minute += 10) {
int second = random.nextInt(60);
String time = String.format("%02d:%02d:%02d", hour, minute, second);
String location = locations[random.nextInt(locations.length)];
String position = String.format("{\"date\":\"%s\",\"location\":\"%s\",\"pos\":\"中国浙江省嘉兴市南湖区富润路257号\"}", time, location);
positions.add(position);
}
}
// 输出所有的坐标点
for (String position : positions) {
System.out.println(position);
}
}
}
```
这个程序会随机生成从早上 00:00:00 开始,每隔 10 分钟一个坐标点,到晚上 23:59:59 结束的所有坐标点,并将它们以 JSON 格式输出。其中,坐标点的位置信息是在预设的位置数组中随机选择的。
阅读全文