Android MapActivity : Couldn't get connection factory client

electricSunny picture electricSunny · May 15, 2011 · Viewed 59.6k times · Source

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

Answer

Diego Frehner picture Diego Frehner · Jun 2, 2011

i had exactly the same initial situation as you described.

when you see the map tiles there are obviously some missing to see a position on the map:

1. you need a location. i recognized that setting only a geo position via DDMS view to the emulator is not enough. you have to explicitly press every time the "Send" button in DDMS to trigger a location update on your emulator. (just to mention: on a real the device you have sometimes to walk a bit to make your device get a location update ;), i was so pissed off until i walked around thinking of what to do now ^^)

2. you need a correct implementation of ItemizedOverlay with an correct OverlayItem. i wrote my own overlay which got bit "complicated". if you're not sure if your implementation is correct, use this guide to create an implementation with minimal changes Map view tutorial android developers

or use this:

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

i want specially point out that you must call boundCenter or boundCenterBottom on the drawable. else it will not be drawn. be also careful if you use different markers in the same overlay with overlayItem.setMarker, that u call it there too.

3. you have to move the view on the map to your point. you can achieve this like this:

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

i recognized that the function mapController.zoomToSpan does not work. (at least for me, i am still developing on this app). maybe its the same with animateTo. i did not try. set center works. (and setZoom level also).

Maybe there is something in the points i mentioned which could lead to, that your map does not work like you want.

Good luck!

edit: i forgot to mention that i am still getting that factory client error even it works to get a valid location, real on device and fake on emulator via ddms send). i just ignore for now.