Android MapActivity : Couldn't get connection factory client
Asked Answered
V

8

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

Varion answered 15/5, 2011 at 6:17 Comment(2)
@funaktron: "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" -- that error has nothing to do with your code. Everyone gets that, even with working code. With respect to your problem, I have never tried using MyLocationOverlay on an emulator with an actual fix, so I have no idea if it works. SDK 8 emulator is actually the good one. Do not use SDK 9/10 emulators, as they will crash when you try setting the fake location. SDK 11 emulator should work, if it is not too slow for you.Yonder
@CommonsWare: Thanks for the post. After further tests, the same code works on the Device, that is the map location overlay works, so its obviously just an emulator thing. Though its interesting that nobody can answer why the error appears; the question still remains.Varion
A
6

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.

Autoicous answered 2/6, 2011 at 12:57 Comment(2)
Diego,thanks for the response. I'm going to give it whirl and get back to you. CheersVarion
I'cant get the library work in the device if i sign the APK file. If i start in Debug-Mode it works very well... any ideas?Cornetcy
E
4

Please make sure that you use permissions in your application AndroidManifest.xml.

add these 3 lines in AndroidManifest.xml

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

And also make sure keystore is pointing to the keystore you created.

In eclipse Check Window -> Preferences ->Android ->Build : Default Debug keystore, is pointing to the key you created using keytool, else use Browse button and point to the actual key.

Elanaeland answered 10/1, 2012 at 14:15 Comment(1)
ACCESS_COARSE_LOCATION is not necessary.Danialdaniala
D
4

Hello fellow developers,

I too experienced this issue and spent nearly half a day trying to figure out what was going on. Initially the map activity would not display at all and I was receiving an error stating, "Couldn't get connection factory client" which in turn created another error, "java.io.IOException: Server returned 3".

The cause of this is that Google have failed to communicate effectively to their development base that whilst in development, i.e. prior to signing and releasing your application, you must sign your application with a debug key which is used whilst testing. To do so, follow the method below replacing the [password] and [key password] with your own passwords.

From your .android directory, issue the following command:

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

Upon doing the above you will be pleased to receive your MD5 Certificate fingerprint which you can use to sign up for your Google maps API key. Replace your Google Maps API key in your project, do a Project Clean and re-run your applicat6ion. You should now be able to view your Google Map and be rid of your annoying errors.

How to obtain a Google Maps Android API Key

Doubleacting answered 2/8, 2012 at 3:39 Comment(2)
if above command does not work, try using android, android for both passwords.Doubleacting
i did the same thing which you have mentioned but now working and showing same error.Artur
F
2

I faced the same problem and the problem was that I missed when I set the appropriate layout to the MapActivity the code was

setContentView(R.layout.main);

the main.xml layout file doesn't contain any mapview

it became

setContentView(R.layout.mapview) 

which have the following XML code

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

The map is working fid right now , hope this would help

Also you can check if you 've added any thing to your mapview layout because adding such views would result in this error

Firsthand answered 23/11, 2011 at 12:13 Comment(0)
W
2

I had the same problem with "MapActivity Couldn't get connection factory client" The way I fixed the problem was very simple! I just uninstalled entire application and reinstalled it. It worked!!!

Wrest answered 14/3, 2012 at 2:58 Comment(4)
Hello there! I got that issue too...so i wanna ask, what do you mean by reinstall the app?coz we just run it in the emulator...do you mean to reinstall our app in the emulator? Thanks in advance! :DArawakan
i also am facing the same issue and i also dont understandin what installing and uninstalling it , we use the simple emulatorGadabout
To me it stopped working after playing with different versions of the sdk. Trying to set it back to first version but without success. Almost quit trying when i got another idea: why not restarting phone after un installing and reinstalling the app. finally, it worked.Anlage
i have un-istalled & re-installed the app on emulator as well as on actual device but this is not working.Artur
H
0

I had the same problem with below 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>

Then i changed the main.xml to as below, the problem was solved

<?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"
/>
Hauteur answered 9/5, 2012 at 7:4 Comment(0)
L
0

There seem to be mulitple reasons for this happening. I've fixed it altering my project build target to api 10 (rclick on the project /Properties/Android) and then running on an emulator at api level 15 (albeit very, very slowly!).

Landlady answered 1/8, 2012 at 12:36 Comment(0)
O
0

Somebody up there already said it in a comment: Restart the phone. Or if you're running in emulator: Restart the emulator.

Or answered 15/3, 2013 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.