Android MapView 未加载

发布于 2024-09-25 11:21:10 字数 3497 浏览 0 评论 0原文

我的 MapView 遇到问题,因为它没有加载地图。我查了一下资料,发现很多人都有同样的问题。我检查了所有可能的问题,似乎一切正常:P

  • 在清单上,在标签内

  • 我在标签之前有 < /p>

  • 在模拟器中,3G 工作正常,因为我可以使用浏览器导航,并且 Google 地图加载完美

  • 我检查了两次我的 ApiKey,看起来没问题。我使用Windows,所以在cmd中我导航到Java Keytool所在的文件夹,一旦在那里我执行下一个命令来获取指纹,然后我的ApiKey:

keytool -list -alias androiddebugkey -storepass android -keypass android -key store c:\path\where\the\file\is\ located\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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫九 2024-10-02 11:21:10

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

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

  2. 我们使用位于工具目录中的 android“emulator”命令从命令行启动模拟器,并使用代理选项启动,而不是从 Eclipse 启动它,例如:

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

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

山有枢 2024-10-02 11:21:10

您没有解释“它未加载地图”的含义,这使得很难帮助您。

您在粘贴的代码中没有提供有效的 API 密钥,这使得我们更难为您提供帮助。

这是一个正在运行的 MapView 项目 -- 只需粘贴您自己的 API 密钥。如果失败,但独立地图应用程序在同一模拟器/设备中运行良好,则您的 API 密钥可能无效。

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.

瞄了个咪的 2024-10-02 11:21:10

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

“ApiKey 是正确的,其他一切也都是正确的,除了清单上的 Internet 使用权限。我错误地将 INTERNET 输入为 INERNET Ø_Ø”我不明白为什么 Eclipse 不发出警告那个:P”

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文