问题
I am trying include google map in my android application.
I gone through this procedure to get the Map API key.
After getting the key i wrote the following code to display the map in my application.
My Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mymap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.mymap.LocationActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Layout
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="mykey"
android:clickable="true"
android:enabled="true" />
When i run the application i am getting an exception like this.
03-28 14:31:14.868: W/System.err(21147): IOException processing: 26
03-28 14:31:14.868: W/System.err(21147): java.io.IOException: Server returned: 3
03-28 14:31:14.868: W/System.err(21147): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
03-28 14:31:14.868: W/System.err(21147): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
03-28 14:31:14.868: W/System.err(21147): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
03-28 14:31:14.868: W/System.err(21147): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
03-28 14:31:14.868: W/System.err(21147): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
03-28 14:31:14.868: W/System.err(21147): at java.lang.Thread.run(Thread.java:856)
Please help me to solve this.
回答1:
Remember MapView is depreciated. Google maps V2 is supported. and you cant get a new map v1 api key.
visit here to lean more about maps v2
if you are already using v2 :
Try to add following data to your manifest:
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.ikolmobile.magicmap.permission.MAPS_RECEIVE" />
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR KEY HERE" />
回答2:
This is a known error when you have a problem with your API key:
take a look at the following posts:
android, google map errors: BaseTileRequest, Server returned: 3
Google map signed api key errors in Android
UPDATE:
from the link you posted for getting the Key you are getting a key for Google Map API V2 and hence it wont work with Google Maps API V1.
To integrate Google Map API V2 you can follow this blog post I wrote on this topic:
Google Map API V2
来源:https://stackoverflow.com/questions/15678344/mapview-in-android-application