Android MapView not loading tiles on devices
I am writing an Android application that uses Google Maps MapView to display maps. The application works fine in the emulator, but when I try to run it on an actual device it will not load any map tiles.
I have already done the following:
- Checked that Eclipse ADT is configured with the default debug keystore
- I have regenerated the Google Maps API key against the debug keystore
- Checked that the application has access to the internet for the application also connects to a different server and that works ok.
- I have checked and re-checked all the tips that are found in other similar question, but in case I have missed anything I have attached the res/layout file and the android manifest file.
Layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0AVJ6OY3X1uWHCbkTOJx7ajC-TWI44phQofTSlg"
/>
</RelativeLayout>
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<uses-library android:name="com.google.android.maps" android:required=开发者_运维技巧"true"/>
<activity android:name="DummyMap"
android:label="@string/app_name">
</activity>
<activity android:name="Dummy" android:label="@string/app_name" android:theme="@android:style/Theme.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ContactActivity" android:theme="@android:style/Theme.Light"></activity>
<activity android:name="DummyPreferences"></activity>
</application>
</manifest>
Any tips are welcome as I am now at the point where I have to randomly try to make changes to these file to see if anything works.
I see in Android reference document (http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_COARSE_LOCATION):
ACCESS_COARSE_LOCATION Allows an application to access coarse (e.g., Cell-ID, WiFi) location
But because you're running app on device, so you should add additional permission: ACCESS_FINE_LOCATION
because with this permission, your device can get location by GPS
ACCESS_FINE_LOCATION Allows an application to access fine (e.g., GPS) location
I found the cause of the problem at last.
In my subclass of MapActivity I had a onResume() method that called super.onStop()! Changing that to super.onResume() fixed the problem.
精彩评论