java - 无法放大整个国家,java Google Maps V2

标签 java android google-maps google-maps-api-2

我正在开发一个项目,其中的 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/

相关文章:

java - GWT 开发模式不工作(配置 web.xml)

java - 从子类调用 awt Frame 方法

java - 在 java/c++/c/actionscript-3 应用程序中使用静态变量的最佳方法是什么?

javascript - 在 Google map 中推送新的 LatLng

google-maps - Google Map OpenLayers Kml 图标名称

google-maps - JQuery Mobile - 用 map 填充内容 div,无滚动

java - Maven wildfly-maven-plugin 自定义standalone.xml

android - 我想使用数字日期选择器对话框和时间选择器对话框

android - 如何在多个 Activity 中使用服务?

java - 使用 2 个字符串集(组合它们)