0

需要緊急幫助 - 在使用以前的Maps API時 - 在插入以下Maps v2 API的代碼段後,地圖不會加載。 CustomMapView是繼承MapView的Java類。不能理解所有參數應該被替換或刪除嗎?Google Maps APIv2 - 無法加載地圖

<com.stub.android.ui.CustomMapView 
     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="0xxxxxxxxxxxxxxxxxxxxx" /> 

伊夫加在清單如下 -

<permission 
    android:name="com.stub.android.ui.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature" /> 

<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true" /> 

<uses-permission android:name="com.stub.android.ui.permission.MAPS_RECEIVE" /> 
<meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AIxxxxxxxxxxxxxxx" /> 

代碼爲CustomMapView類

public class CustomMapView extends MapView { 

public CustomMapView(Context context, String apiKey) { 
    super(context, apiKey); 
    // this.context = context; 
} 

@Override 
public boolean dispatchTouchEvent(MotionEvent ev) { 
    try { 
     return super.dispatchTouchEvent(ev); 
    } catch (Exception ex) { 

     int zoomLevel = getZoomLevel(); 
     getController().setZoom(zoomLevel-1); 
     super.setVisibility(View.GONE); 
     super.setVisibility(View.VISIBLE); 
    } 
    return true; 
} 

@Override 
public void draw(Canvas canvas) { 
    try { 
     super.draw(canvas); 
    } catch (Exception e) { 
     int zoomLevel = getZoomLevel(); 
     getController().setZoom(zoomLevel-1); 
     super.setVisibility(View.GONE); 
     super.setVisibility(View.VISIBLE); 
    } 
} 

public CustomMapView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    // this.context = context; 
} 

public CustomMapView(Context context, AttributeSet attrs) { 
    super(context, attrs); 


} 

@Override 
public boolean onTouchEvent(MotionEvent ev) { 
    System.gc(); 
    return super.onTouchEvent(ev); 
}} 

回答

0
<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="17" /> 

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="com.example.towntour.permission.MAPS_RECEIVE" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 

<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true" /> 

<permission 
    android:name="com.temp.android.maps.googlev2.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature" /> 

<uses-permission android:name="com.temp.android.maps.googlev2.permission.MAPS_RECEIVE" /> 
<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.Black.NoTitleBar" > 
    <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AIzaSyDp6PHK3NYNwS74cKGmX-xc4LuH_uM1mIo" /> 

    <activity 
     android:name="com.temp.android.SplashScreenActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

</manifest> 
+0

我想了解在XML佈局中所做的更改,而不是清單 – Droido

0
Use This XML 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 


<fragment 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.SupportMapFragment" /> 

+0

如何在現有的xml佈局中合併相同的問題,包括在佈局中的java mapview類, – Droido

+0

只是在你現有的xml代碼中設置這個xml ...並運行它..它會正常工作... –

+0

你沒有得到我,在這種情況下應該爲MapView java類做什麼? – Droido

0
This Way will be usefull for that.. 


public class HelloGoogleMaps extends MapActivity 
{ 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 

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


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

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

<uses-permission android:name="android.permission.INTERNET"/> 
+0

我如何在XML佈局中使用HelloGoogleMaps類,就像我在我的代碼APIv2 - Droido

+0

其活動你不能使用它..你好GoogleMaps ...對於地圖類將來自它的庫..u不能這樣做先生.......... –

+0

我一直在使用這段代碼http://pastebin.com/87qY2hj1這是一個自定義的類,它擴展了MapView,我通過包名稱包含在我的佈局中,因爲它是可重用的組件 – Droido