谷歌地图图块无法加载

发布于 2024-12-07 22:20:19 字数 3903 浏览 0 评论 0原文

我正在为 Android 开发一个简单的 Google 地图应用程序。我正在使用 Eclipse 和 Android 虚拟设备。运行应用程序时,没有显示图块,并且我收到消息“无法获取连接工厂客户端”。

我读过,看起来这是一个错误,但有些人说他们的应用程序可以正常工作。我尝试过在我的虚拟设备 (2.2) 上使用 API 1.6、2.1、2.2,但它们都不起作用。

我从 debug.keystore 获得的 MD5 中获取了 API 密钥。

我该如何解决这个问题?我刚刚找到了有同样问题的人,但有解决方案。

清单:

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

    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <uses-library android:name="com.google.android.maps"/>
        <activity android:name=".SimpleMap2Activity"
                  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>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
    </uses-permission>
    <uses-permission android:name="android.permission.INTERNET" >
    </uses-permission>
    <user-permission android:name="android.permission.ACCESS_COARSE_LOCATION">
    </user-permission>
</manifest>

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.google.android.maps.MapView
    android:id="@+id/mapview1"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:enabled="true" 
    android:clickable="true" 
    android:apiKey="0YSU8-p-YkHYQ2lit-vAsh2U0jW5zV3l_YQVlvw" />    

</LinearLayout>

代码:

package uniovi.pfc;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

public class SimpleMap2Activity extends MapActivity {

    private MapView mapView=null;
    private MapController mapController=null;
    private GeoPoint geoPoint=null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapview1);
        mapController = mapView.getController();

        String coordinates[] = { "40.747778", "-73.985556" };
        double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);

        geoPoint = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));

        mapController.animateTo(geoPoint);
        mapController.setZoom(5);
        mapView.invalidate();
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_I:
            mapController.zoomIn();
            break;
        case KeyEvent.KEYCODE_O:
            mapController.zoomOut();
            break;

        }
        return super.onKeyDown(keyCode, event);
    }

}

I'm developing a simple Google Maps app for Android. I'm using Eclipse and an Android Virtual Device. When running the app, no tiles are shown, and I get the message "Couldn't get connection factory client".

I've read and looks like it is a bug, but some people say they got their apps working. I've tried using API 1.6, 2.1, 2.2 over my virtual device (2.2) and none of them work.

I got my API key from the MD5 obtained from the debug.keystore.

How can I solve the problem? I just found people with the same problem, but any solutions.

Manifest:

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

    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <uses-library android:name="com.google.android.maps"/>
        <activity android:name=".SimpleMap2Activity"
                  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>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
    </uses-permission>
    <uses-permission android:name="android.permission.INTERNET" >
    </uses-permission>
    <user-permission android:name="android.permission.ACCESS_COARSE_LOCATION">
    </user-permission>
</manifest>

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.google.android.maps.MapView
    android:id="@+id/mapview1"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:enabled="true" 
    android:clickable="true" 
    android:apiKey="0YSU8-p-YkHYQ2lit-vAsh2U0jW5zV3l_YQVlvw" />    

</LinearLayout>

Code:

package uniovi.pfc;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

public class SimpleMap2Activity extends MapActivity {

    private MapView mapView=null;
    private MapController mapController=null;
    private GeoPoint geoPoint=null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapview1);
        mapController = mapView.getController();

        String coordinates[] = { "40.747778", "-73.985556" };
        double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);

        geoPoint = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));

        mapController.animateTo(geoPoint);
        mapController.setZoom(5);
        mapView.invalidate();
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_I:
            mapController.zoomIn();
            break;
        case KeyEvent.KEYCODE_O:
            mapController.zoomOut();
            break;

        }
        return super.onKeyDown(keyCode, event);
    }

}

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

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

发布评论

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

评论(1

空城之時有危險 2024-12-14 22:20:19

最后,问题是地图 apiKey。这个话题在互联网上没有得到很好的解释。

简而言之,我将解释如下:

  1. 要在 Android 虚拟机中使用映射,您可以使用 debug.keystore
  2. 要在真实的 Android 设备中使用映射,您需要在新的密钥库中创建一个密钥。如果您右键单击该项目并导出为签名的 apk,Eclipse 可以为您完成此操作。
  3. 在这两种情况下,您都需要转到控制台,并在 java jdk /bin/ 文件夹中执行名为 keytool.exe 的 Java 工具。
  4. 如果 keytool 为您提供 SHA1 代码而不是 MD5,则问题可能是您使用的是 Java 7。将 -v 参数添加到 keytool 调用以进入详细模式,您还将获得 Google 要求您提供的 MD5。

Finally, the problem was the maps apiKey. This topic is not very well explained over the internet.

Shortly, I would explain as following:

  1. To use maps into an Android Virtual Machine, you use debug.keystore
  2. To use maps into a real Android device, you need to create a key into a new keystore. Eclipse can do it for you if you right-click the project and export as a signed apk.
  3. In both cases, you need to go to console, and execute a Java tool called keytool.exe at java jdk /bin/ folder.
  4. If keytool gives you the SHA1 code and not the MD5, the problem can be that you are using Java 7. Add -v parameter to the keytool call to enter verbose mode, and you'll get also the MD5 Google asks you for.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文