Java 当标记距离太远时,Google map api不会在屏幕上显示所有标记
我试图显示一条多段线,但我无法使地图的标记适合我的手机屏幕 我在谷歌地图上有两个标记 如果这两个标记不是很遥远,那么一切正常,这两个标记在屏幕上是可见的 但是,如果这两个标记非常遥远,则这两个标记在屏幕上不可见 下面是我的代码:Java 当标记距离太远时,Google map api不会在屏幕上显示所有标记,java,google-maps,google-maps-android-api-2,Java,Google Maps,Google Maps Android Api 2,我试图显示一条多段线,但我无法使地图的标记适合我的手机屏幕 我在谷歌地图上有两个标记 如果这两个标记不是很遥远,那么一切正常,这两个标记在屏幕上是可见的 但是,如果这两个标记非常遥远,则这两个标记在屏幕上不可见 下面是我的代码: static final LatLng HAMBURG = new LatLng(46.227638, 2.213749); // for example static final LatLng HAMBURG_2 = new LatLng(-44.339565,147
static final LatLng HAMBURG = new LatLng(46.227638, 2.213749); // for example
static final LatLng HAMBURG_2 = new LatLng(-44.339565,147.637862); // for example
MapView map;
map = findViewById(R.id.mapView);
map.onCreate(null);
map.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(final GoogleMap googleMap) {
googleMap.addMarker(new MarkerOptions()
.position(HAMBURG)
.title("First Pit Stop")
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
googleMap.addMarker(new MarkerOptions()
.position(HAMBURG_2)
.title("Wrong Turn!")
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
PolylineOptions options = new PolylineOptions().width(5).color(Color.BLACK);
options.add(pos_1, pos_2);
googleMap.addPolyline(options);
}
});
map.onResume();
}
});
如何在屏幕上显示所有制造商
如何让所有制造商都适合屏幕
我该怎么办
谢谢。用以下内容更新您的代码:
int padding = 0;
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(pos_1);
builder.include(pos_2);
LatLngBounds bounds = builder.build();
final CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
googleMap.animateCamera(cu);
PolylineOptions options = new PolylineOptions().width(5).color(Color.BLACK);
options.add(pos_1, pos_2);
googleMap.addPolyline(options);
}
});