2012-06-13 29 views
0

我需要使用地圖上運行的物理Android設備, 我該怎麼做?如何在物理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) 
+1

您是否在清單中使用Google API版本? – BDFun

+0

我不知道你的意思? – IamStalker

回答

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

你給了互聯網訪問權限嗎? –

+0

是的,我做了,我想我做了所有的事情:( – IamStalker

+0

你試過我的代碼??你可能會得到這個想法...嘗試一次.. –

相關問題