开发者

Google maps tiles doesn't load

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 MapControl开发者_运维技巧ler 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);
    }

}


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜