2010-09-28 58 views
1

我的MapView出现问题,因为它没有加载地图。我一直在阅读,并发现许多人有同样的问题。我检查所有可能存在的问题,似乎一切正常:PAndroid MapView未加载

  • 在清单中,是标签

  • 我有标签之前

  • 在仿真器内部3G工作正常,因为我可以导航浏览器和谷歌地图加载完美

  • 我检查了两次我的ApiKey,似乎没事。使用Windows系统,因此在cmd我导航到Java keytool的所在的文件夹,一旦有我执行下一指令Im来获取指纹,然后我ApiKey:

的keytool -list -alias androiddebugkey -storepass的android -keypass机器人 - 键器C:\路径\其中\中\文件\是\位于\ debug.keystore

下面是我的一些代码:

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); 
    } 

的XML布局:

<?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> 

所以,我不知道我能做些什么来解决这个问题。

任何人都可以帮助我吗? :D

回答

0

很久以前,因为我解决了这个问题(正如我在CommonsWare答案中给出的评论中所解释的)。只是写在这里,使其“官方”xD:

“ApiKey是正确的,除了互联网使用权限Manifiest之外,其他一切都是正确的我错误地键入INTERNET到INERNET¬_'我不明白为什么Eclipse不提醒:P“

1

你不解释什么“它没有加载地图”的意思,这使得它很难帮助你。

您不会在粘贴的代码中提供有效的API密钥,这使得帮助您变得更加困难。

Here is a working MapView project - 只需粘贴您自己的API密钥。如果失败了,独立的Maps应用程序在相同的仿真器/设备上工作正常,那么您的API密钥可能无效。

+1

”未加载“是指MapView显示正常,但我能看到的唯一东西是灰色方块,意思是”地图未加载“。无论如何,我发现我的问题的解决方案,ApiKey是正确的,除了互联网使用权限Manifiest之外,其他一切都是正确的。我错误地将INTERNET输入INERNET¬_¬'我不明白为什么Eclipse不会提醒你:P – Kitinz 2010-10-01 08:45:44

2

我们的Android开发者也面临这个问题。我们解决了这样的问题:

  1. 我们从每台机器生成API密钥,并将Key添加到它们各自的main.xml文件中。所以每个开发人员都有一个单独的api密钥。

  2. 我们使用它位于tools目录中的机器人“仿真器”命令启动命令行模拟器,开始与代理选项,而不是从Eclipse中如开始吧:

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

+0

谢谢,波波森 – 2011-08-07 05:19:23