除非您触摸地图视图,否则不会加载Android MapView [英] Android MapView does not load unless you touch on the mapview

查看:85
本文介绍了除非您触摸地图视图,否则不会加载Android MapView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在android应用程序中添加了一个mapview.我在清单中使用了正确的设置,现在我遇到了问题.当我去有地图的地方时,它仅显示画布,但不显示地图.如果我仅触摸它,它将开始加载.即使这样,它也无法完全加载.它只能加载到一定水平.如果我不断触摸屏幕,它将持续加载.但是即使那样,我也无法放大或缩小,甚至无法移动地图.有解决方案吗?我做错了什么吗?

I have added a mapview in my android application.I have used correct settings in the manifest and now i'm facing a problem. When i go to the place where i have my map,it displays only the canvas but not the map. If i touch on it only it starts loading. Even then it does not fully load.it loads only to a certain level.if i keep touching the screen it continuously loads. But even then i cannot zoom in or out OR cant even move the map. Is there a solution for this? Have i done something wrong?

我的代码

            MapView mapView;
            GoogleMap map;





             mapView = (MapView)view.findViewById(R.id.map);
             Bundle savedInstanceState = null;
            mapView.onCreate(savedInstanceState);

                // Gets to GoogleMap from the MapView and does initialization stuff
                map = mapView.getMap();
                map.getUiSettings().setMyLocationButtonEnabled(false);
                map.setMyLocationEnabled(true);

                MapsInitializer.initialize(activity);

                double lat;
                double lon;

                lat = Double.parseDouble(theaterDetail.getLatitude());
                lon = Double.parseDouble(theaterDetail.getLongitude());

                // Updates the location and zoom of the MapView
                map.addMarker(new MarkerOptions().position(
                        new LatLng(lat, lon)).title(theaterDetail.getAddress()));

                final LatLng THEATER_POSITION = new LatLng(lat, lon);

                CameraPosition cameraPosition = new CameraPosition.Builder()
                        .target(THEATER_POSITION) // Sets the center of the map to
                                                    // THEATER_POSITION
                        .zoom(10) // Sets the zoom
                        .bearing(360) // Sets the orientation of the camera to east
                        .tilt(30) // Sets the tilt of the camera to 30 degrees
                        .build(); // Creates a CameraPosition from the builder
                        map.animateCamera(CameraUpdateFactory
                        .newCameraPosition(cameraPosition));

xml

<com.google.android.gms.maps.MapView 
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="1"/>  

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.***.***"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"
        />

     <permission
    android:name="com.***.***.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

     <uses-permission android:name="com.***.***.permission.MAPS_RECEIVE" />






    <application
        android:name="com.***.***.service.CommonVariable"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppBaseTheme"
        android:hardwareAccelerated="true" >

        <meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />


        <!-- <uses-library android:name="com.google.android.maps" />  --> 

        <activity
            android:name="com.***.***.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.Sherlock.Light.DarkActionBar"
            android:windowSoftInputMode="adjustPan" 
            android:hardwareAccelerated="true">
        </activity>

        <activity 
             android:name="com.***.***.Map"
            android:label="@string/app_name"
            android:theme="@style/Theme.Sherlock.Light.DarkActionBar" ></activity>

        <activity
            android:name="com.***.***.WelcomeActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.Sherlock.NoActionBar"
            android:hardwareAccelerated="true" >
            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
                    android:name="com.google.android.maps.v2.API_KEY"
                    android:value="*********************" />


    </application>

</manifest>

推荐答案

尽管这是一个老问题,但我在这里提供了对我有用的方法.该解决方案有效的原因是它覆盖了onResume()处理程序.如果使用的是mapView,则需要从onResume()处理函数中调用mapView.onResume().示例:

Though this is an old question, I am providing here what worked for me. The reason that this solution works is that it overrides the onResume() handler. If you are using a mapView, you need to call mapView.onResume() from the onResume() handler. Example:

@Override
public void onResume() {
    mMapView.onResume();
    super.onResume();
}

这篇关于除非您触摸地图视图,否则不会加载Android MapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆