14

I'm trying to get the Map demos working, as provided in the Google API sample projects.  I am using AVDs and have tried with versions 8, 10 and 11 and get the same issue.

I've generated my own debug key and added to the project.  I can see the map on app start up, and can zoom in etc - so I am getting the map tiles, fine. Yes - I have the correct permissions and  library set in the Manifest file (as per samples).

But, I cannot set a location on the map, either via DDMS or Telnet.  I see the following error in LogCat: MapActivity : Couldn't get connection factory client

I've read numerous threads regarding this issue, but they always seem to be as a result of a bad API key; which I do not have, as I am retrieving map tiles.

So I created my own project to test this further, and am executing the following code on initialisation of my map:

    myLocationOverlay = new MyLocationOverlay(this, mapView);
       mapView.getOverlays().add(myLocationOverlay);
       myLocationOverlay.enableCompass();
       myLocationOverlay.enableMyLocation();
       Log.i("funkatron: ", "ABOUT TO CALL RUN ON FIRST FIX");
       myLocationOverlay.runOnFirstFix(new Runnable() {
           public void run() {
               String loc = "we have a location, executing AnimateTo().
"+myLocationOverlay.getMyLocation().toString();
               Log.i("funkatron:",loc);

mapController.animateTo(myLocationOverlay.getMyLocation());
           }
       });

I see my first log statement, but never the second, and "MapActivity : Couldn't get connection factory client" is written to LogCat at that point.

I have read that there were issues with SDK v8 emulators, so I have tried with v10 and 11 - but still no joy. I have NOT yet tried this on an actual device - will do soon.

Any help on this issue would be greatly appreciated - it's really baffling me  ;)

cheers

4

8 回答 8

6

我的初始情况与您描述的完全相同。

当您看到地图图块时,显然缺少一些在地图上查看位置的信息:

1.你需要一个位置。我认识到仅通过 DDMS 视图将地理位置设置到模拟器是不够的。您必须每次在 DDMS 中显式按下“发送”按钮以触发模拟器上的位置更新。(顺便提一下:在真正的设备上,您有时需要走一点才能让您的设备获得位置更新;),我很生气,直到我四处走动,想现在该做什么^^)

2. 您需要使用正确的 OverlayItem 正确实现 ItemizedOverlay。我写了自己的叠加层,有点“复杂”。如果您不确定您的实现是否正确,请使用本指南创建一个更改最少的实现地图视图教程 android 开发人员

或使用这个:

private class MyItemizedOverlay extends ItemizedOverlay {
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

    public MyItemizedOverlay(Drawable defaultMarker) {
          super(boundCenterBottom(defaultMarker));
    }

    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
      return mOverlays.get(i);
    }

    @Override
    public int size() {
      return mOverlays.size();
    }
}

private void updateLocationOverlay() {
    if (location == null) { return };
    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.XXXX);
    MyItemizedOverlay myItemizedOverlay = new MyItemizedOverlay(drawable);
    GeoPoint point = new GeoPoint((int)(location.getLatitude() * 1E6), (int)(location.getLongitude() * 1E6));

    OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
    myItemizedOverlay.addOverlay(overlayitem);
    mapOverlays.add(myItemizedOverlay);
}

我想特别指出,您必须在可绘制对象上调用 boundCenter 或 boundCenterBottom。否则它不会被绘制。如果您使用overlayItem.setMarker 在同一个叠加层中使用不同的标记,也要小心,您也在那里调用它。

3.您必须将地图上的视图移动到您的位置。你可以这样实现:

MapController mapController = mapView.getController();
mapController.setCenter(point)

我认识到函数 mapController.zoomToSpan不起作用。(至少对我来说,我仍在开发这个应用程序)。也许它与animateTo相同。我没有尝试。设置中心工作。(还有 setZoom 级别)。

也许我提到的几点可能导致您的地图无法按照您的意愿工作。

祝你好运!

编辑:我忘了提到我仍然收到那个工厂客户端错误,即使它可以通过ddms发送获得有效的位置,在设备上是真实的,在模拟器上是假的)。我暂时忽略。

于 2011-06-02T12:57:04.387 回答
4

请确保您在应用程序 AndroidManifest.xml 中使用权限。

在 AndroidManifest.xml 中添加这 3 行

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>

还要确保密钥库指向您创建的密钥库。

在 eclipse Check Window -> Preferences -> Android -> Build : Default Debug keystore 中,指向您使用 keytool 创建的密钥,否则使用浏览按钮并指向实际密钥。

于 2012-01-10T14:15:38.160 回答
4

各位开发者您好,

我也遇到过这个问题,花了将近半天的时间试图弄清楚发生了什么。最初,地图活动根本不会显示,我收到一条错误消息,指出“无法获取连接工厂客户端”,这反过来又产生了另一个错误,“java.io.IOException:服务器返回 3”。

造成这种情况的原因是谷歌未能与他们的开发基地进行有效的沟通,即在开发过程中,即在签署和发布您的应用程序之前,您必须使用在测试时使用的调试密钥对您的应用程序进行签名。为此,请按照以下方法将 [password] 和 [key password] 替换为您自己的密码。

在您的 .android 目录中,发出以下命令:

keytool -list -alias androiddebugkey -keystore debug.keystore storepass [password] -keypass [key password]

完成上述操作后,您将很高兴收到您的 MD5 证书指纹,您可以使用它来注册您的 Google 地图 API 密钥。在您的项目中替换您的 Google Maps API 密钥,执行项目清理并重新运行您的应用程序。您现在应该能够查看您的 Google 地图并摆脱烦人的错误。

如何获取 Google Maps Android API 密钥

于 2012-08-02T03:39:28.043 回答
2

“MapActivity 无法获取连接工厂客户端”我遇到了同样的问题我解决问题的方法非常简单!我刚刚卸载了整个应用程序并重新安装了它。有效!!!

于 2012-03-14T02:58:00.463 回答
2

我遇到了同样的问题,问题是当我为 MapActivity 设置适当的布局时我错过了代码是

setContentView(R.layout.main);

main.xml 布局文件不包含任何地图视图

它变成了

setContentView(R.layout.mapview) 

具有以下 XML 代码

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
    <com.google.android.maps.MapView
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="YOU_API_KEY"
        />
</LinearLayout>

地图现在正在工作中,希望这会有所帮助

您还可以检查是否在地图视图布局中添加了任何内容,因为添加此类视图会导致此错误

于 2011-11-23T12:13:44.167 回答
0

我在main.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
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="Your API-KEY"
    />

</LinearLayout>

然后我把main.xml改成如下,问题就解决了

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="Your API-KEY"
/>
于 2012-05-09T07:04:38.797 回答
0

发生这种情况似乎有多种原因。我已经修复了它,将我的项目构建目标更改为 api 10(单击项目/Properties/Android),然后在 api 级别 15 的模拟器上运行(尽管非常非常慢!)。

于 2012-08-01T12:36:08.193 回答
0

上面有人已经在评论中说:重启手机。或者,如果您在模拟器中运行:重新启动模拟器。

于 2013-03-15T10:19:02.030 回答