如何在物理android设备上使用地图?

时间:2012-06-13 09:16:10

标签: android google-maps android-mapview

我需要在物理Android设备上运行地图, 我该怎么做?

我不想使用AVD进行调试。

顺便说一下,我在AVD上遇到同样的错误,请帮忙吗? 这是我的代码

<com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:apiKey="0enZtoViiB7JtEUxmyjwYWuw0Hz8pdTqNNWtBjQ"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true" />

的AndroidManifest.xml

<uses-library android:name="com.google.android.maps" />

的活动:

public class AroundMeActivity extends MapActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.qa_layout_activity);

    MapView mapView = (MapView) findViewById(R.id.map);
    mapView.setBuiltInZoomControls(true);
}

@Override
protected boolean isRouteDisplayed() {
    return false;
}
}

STACKTRACE:
at android.app.ActivityThread.main(ActivityThread.java:3683)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
        at dalvik.system.DexFile.defineClass(Native Method)
        at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:207)
        at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:200)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)

2 个答案:

答案 0 :(得分:2)

Exception通常表示您的项目中存在符号冲突。 确保您在项目中仅包含maps.jar一次。

答案 1 :(得分:1)

second.java

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
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 com.google.android.maps.Overlay;
public class second extends MapActivity 
{

MapView mapView;
Drawable drawable;
LocationManager locationmanager;
private LocationListener locationListener;
MapController mapController;
private String provider;
Location location;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


            mapView = (MapView) findViewById(R.id.MapView);
            mapView.setBuiltInZoomControls(true);
            mapView.setSatellite(true);
            mapView.setStreetView(true);
            mapController = mapView.getController();
            mapController.setZoom(16);

            GeoPoint point = new GeoPoint(lat,lon);
//lat and lon are integer values for describing the location
            mapView.invalidate();
            mapController.animateTo(point);

}

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="API key"
/>

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.gps22"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <uses-library android:name="com.google.android.maps"/>
        <activity android:name=".second"
                  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>
</manifest>