-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomLoc.java
40 lines (36 loc) · 1.41 KB
/
RandomLoc.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.math.BigDecimal;
import java.util.Random;
public class RandomLoc {
public static void main(String[] args) {
randomLonLat(120.1236537811584, 120.54355740408135, 22.938130677113588, 23.33482567148375);
}
public static void randomLonLat(double MinLon, double MaxLon, double MinLat, double MaxLat) {
File file = new File("./public/location3.json");
try {
if (!file.exists())
file.createNewFile();
} catch (Exception e) {
// TODO: handle exception
}
try {
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("[\n");
Random random = new Random();
for (int i = 0; i < 10000; ++i) {
BigDecimal db = new BigDecimal(Math.random() * (MaxLon - MinLon) + MinLon);
String lon = db.setScale(6, BigDecimal.ROUND_HALF_UP).toString();
db = new BigDecimal(Math.random() * (MaxLat - MinLat) + MinLat);
String lat = db.setScale(6, BigDecimal.ROUND_HALF_UP).toString();
bw.write(" { \"lng\": " + lon + ", \"lat\": " + lat + " },\n");
}
bw.write("]\n");
bw.close();
} catch (Exception e) {
// TODO: handle exception
}
}
}