double min_latitude = 0, min_longitude = 0, max_latitude = 0, max_longitude = 0;
double lat = 0, lng = 0;
try {
for (int i = 0; i < locationData.length(); i++) {
JSONObject item = locationData.getJSONObject(i);
lat = item.getDouble("latitude");
lng = item.getDouble("longitude");
if (i == 0) {
min_latitude = max_latitude = lat;
min_longitude = max_longitude = lng;
continue;
}
if (min_latitude >= lat) {
min_latitude = lat;
}
if (max_latitude <= lat) {
max_latitude = lat;
}
if (min_longitude >= lng) {
min_longitude = lng;
}
if (max_longitude <= lng) {
max_longitude = lng;
}
}
} catch (Exception e) {
// TODO: handle exception
}
LatLng southwest = new LatLng(min_latitude, min_longitude);
LatLng northeast = new LatLng(max_latitude, max_longitude);
// 根据northeast,southwest把所有点都包含进当前显示屏
bounds = new LatLngBounds.Builder().include(northeast).include(southwest).build();
MapStatusUpdate u = MapStatusUpdateFactory.newLatLngBounds(bounds);
// MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(latLng);
mBaiduMap.setMapStatus(u);
多坐标点地图全部显示
最新推荐文章于 2018-07-01 10:26:03 发布