我可以在Google地图上彼此靠近时显示标记,但是当它们之间的距离很高时,我只能看到一个lat& lon。
这是我的代码
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng google_api_lat_lon = new LatLng(lat, lon);
float zoomLevel = 16.0f;
Marker markerAPILocation = mMap.addMarker(new MarkerOptions().position(google_api_lat_lon).title(title).icon(BitmapDescriptorFactory.fromResource(R.drawable.saved_locaitons)));
markerAPILocation.showInfoWindow();
mMap.setMyLocationEnabled(true);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(google_api_lat_lon, zoomLevel));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
// mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMapToolbarEnabled(false);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setScrollGesturesEnabled(false);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(google_api_lat_lon, zoomLevel));
}
我需要在地图中显示两个坐标,只有通过根据距离调整缩放级别才能实现。我试过上面的代码,但它不适合我。
答案 0 :(得分:1)
我通过简单地添加
解决了这个问题 LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(google_api_lat_lon);
builder.include(current_lat_lon);
LatLngBounds bounds = builder.build();
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10));