我正在开发一个项目,其中的 map 显示一个国家(希腊)的 100 个标记。当我的 map 在我的移动 android 手机中启动应用程序时打开时, map 会在非洲缩放,而在平板电脑设备中它会在不同的位置-国家/地区缩放。当我的位置通过我的设备设置被禁用时,就会发生这种情况。第一次加载 map 时,如何将 map 设置为放大整个希腊?在任何安卓设备上安装了应用程序?
请检查下面我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
/**
* Check mMap. In case it is not null then setUpMap
*/
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
当我激活当前位置时,它会放大到我所在位置的第 14 层。启用位置设置后,我需要保留此功能。
// Show the current location in Google Map
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
mMap.animateCamera(CameraUpdateFactory.zoomTo(14));
最佳答案
你可以这样做:
map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f) );
坐标在哪里,例如希腊的“中部”。你需要设置一些 SharedPreference了解该应用是否是第一次打开。
关于java - 无法放大整个国家,java Google Maps V2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29751449/