我试过这段代码;它给出了一些地方但不在给定坐标附近。(纬度和经度)
public List<Point> getCoordinates2() {
List<Point> points=new ArrayList<>();
MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder()
.accessToken(accessToken)
.query(GeocodingCriteria.TYPE_POI)
.country("IN") // ISO 3166 alpha 2 country code for India
.proximity(Point.fromLngLat(78.4983, 17.4399))
.build();
try {
GeocodingResponse response = mapboxGeocoding.executeCall().body();
if (response != null && response.features().size() > 0) {
for (int i = 0; i < response.features().size(); i++) {
CarmenFeature feature = response.features().get(i);
String placeName = feature.placeName();
Point point = (Point) feature.geometry();
points.add(point);
String coordinates = String.format("%f,%f", point.longitude(), point.latitude());
System.out.println(placeName + ": " + coordinates);
}
}
} catch (IOException e) {
}
return points;
}
为此它给出了这样的回应,但我们希望公园、剧院、公共汽车站、火车站和寺庙等公共区域在给定坐标(纬度和经度)的 X 公里范围内
`Point Pleasant Restaurant, Hyderabad, Telangana 500034, India: 78.444396,17.415243
PNT Colony, Vijayawada, NTR, Andhra Pradesh, India: 80.639416,16.538129
Poibeda, Machh Kund, Koraput, Odisha, India: 82.540986,18.584619
Poigai, Vellore, Vellore, Tamil Nadu, India: 79.053124,12.915003
Poigainallur, Arakonam, Ranipet, Tamil Nadu, India: 79.564364,12.903959`
也试过这个代码生成的 POIs 与给定的坐标相关并包含在 bbox 中,但它们被限制为 10 条记录。
public List<Point> getCoordinates() {
List<Point> points = new ArrayList<>();
OkHttpClient client = new OkHttpClient();
String parksTemplesHotelsInJPnagar = "https://api.mapbox.com/geocoding/v5/mapbox.places/park%20and%20temple%20and%20hotels.json?bbox=77.449061%2C12.848347%2C77.695739%2C12.966143&limit=50&proximity=77.5724%2C12.907252&autocomplete=false&access_token="+accessToken;
Request request = new Request.Builder()
.url(parksTemplesHotelsInJPnagar)
.build();
try {
Response response = client.newCall(request).execute();
String responseBody = response.body().string();
JSONArray features = new JSONObject(responseBody).getJSONArray("features");
for (int i = 0; i < features.length(); i++) {
JSONObject feature = features.getJSONObject(i);
JSONArray coordinates = feature.getJSONArray("center");
Point point = Point.fromLngLat(coordinates.getDouble(0), coordinates.getDouble(1));
points.add(point);
String placeName = feature.getString("text");
System.out.println(placeName + ": " + point.longitude() + ", " + point.latitude());
}
} catch (IOException e) {
e.printStackTrace();
}
return points;
}
它给出了这样的回应,但我们想要更多记录,最多 10 条记录。
Banashankari Temple: 77.573312, 12.915979
Ragiguda Temple: 77.593409, 12.91467
Dharmagiri Manjunathaswamy Temple: 77.564309, 12.921
Venkateshwara Swamy Temple: 77.589474, 12.910329
Laxman Rao Park - Pride of JAYANAGAR: 77.580493, 12.918529
Lakshman Rao Park Jayanagar: 77.578719, 12.918843
Raagi Gudda Prasanna Anjaneya Temple: 77.593239, 12.915066
KS Layout Park 2: 77.559655, 12.906428
Devagiri Temple: 77.567178, 12.926082
ISKCON @ Vaikunta Hill: 77.549434, 12.89312
我想获得在 Java 和 Spring Boot (gradle) 中给定坐标(纬度和经度)X 公里范围内的著名和公共区域的列表,如公园、剧院、公共汽车站、火车站和寺庙通过使用 Mapbox?