开发者

Android MapView is not loading

Im having problems with the MapView because its not loading the map. I've been reading around, and find many people with the same issue. I checked all the possible issues and it开发者_JS百科 seems that everything is ok :P

  • On the Manifest, the is inside the tag

  • I have the before the tag

  • In the emulator the 3G is working properly since i can navigate with the browser and Google Maps loads perfectly

  • I checked twice my ApiKey, and seems to be ok. Im using Windows, so in the cmd i navigate to the folder where the Java Keytool is located, once there i execute the next command to get the fingerprint and then my ApiKey:

keytool -list -alias androiddebugkey -storepass android -keypass android -key store c:\path\where\the\file\is\located\debug.keystore

Here is some of my code:

public class mapa extends MapActivity {

 private MapView mMapView = null;  
 private MapController mc = null;


 /** Called when the Activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.mapa);

  GeoPoint gPoint = new GeoPoint(40331175,-3765780);

  mMapView = (MapView) findViewById(R.id.mView);
  mMapView.setSatellite(true);
  mMapView.setBuiltInZoomControls(true);

  mc = mMapView.getController();
  mc.setZoom(15);
  mc.setCenter(gPoint);
     }

The XML layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">

 <com.google.android.maps.MapView
  android:id="@+id/mView"
  android:layout_width="fill_parent" 
  android:layout_height="375dp"
  android:padding="5dp"
  android:enabled="true" 
  android:clickable="true" 
  android:apiKey="My_Api_Key" />

 <RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="3dp"
    android:orientation="vertical">

    <TextView
     android:id="@+id/tMapa"
   android:text="Último dato"
   android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    //Here i have some other info, but its not relevant to the problem, since all this views loads properly :P

   </RelativeLayout>      

 </LinearLayout>

AndroidManifest:

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

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INERNET" />
    <uses-permission android:name="android.permission.WRITE_GSERVICES" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">

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

                <!-- I've got here some others Activities declared -->

  <!-- This is the map Activity -->
  <activity android:name=".mapa"
      android:label="@string/app_name"
      class=".mapa">

  </activity>

 </application>

    <uses-sdk android:minSdkVersion="4" />

</manifest> 

So, i dont know what else can i do to solve the issue.

Can anybody help me? :D


Our Android developers were also facing this problem. We solved the problem like this:

  1. We generated API keys from each machine and added the Key to their respective main.xml file. So each developer had a separate api key.

  2. We started the emulator from the command line using the android "emulator" command which is located in the tools directory and started with the proxy option instead of starting it from Eclipse e g:

E:>emulator -avd New_Device -http-proxy http://202.0.0.203:808


You do not explain what "its not loading the map" means, which makes it difficult to help you.

You do not supply a valid API key in your pasted code, which makes it even more difficult to help you.

Here is a working MapView project -- just paste in your own API key. If that fails, yet the standalone Maps application works fine in the same emulator/device, then your API key is probably invalid.


Long time ago since i solved this problem (as i explain in the comment i made to CommonsWare answer). Just writting it here to make it "official" xD:

"The ApiKey was correct and everything else was also correct except the Internet uses-permission on the Manifiest. I misstyped INTERNET to INERNET ¬_¬' I dont understand why Eclipse dont warn about that :P"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜