0

嗨,我是 android 编程的新手,我遵循了许多教程中的步骤,但我只设法显示了谷歌地图,它只在模拟器和设备上显示瓷砖。提前谢谢了!

这是我的清单:

     <?xml version="1.0" encoding="utf-8"?>
     <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="bi.com.biosensors"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-feature        
        android:glEsVersion="0x00020000"        
        android:required="true"/>


    <uses-permission android:name="bi.com.biosensors.mapdemo.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />  



         <activity
            android:name=".SplashScreen"
            android:label="@string/app_name"  >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        </activity>
        <activity android:name=".BiMain"
            android:configChanges="keyboardHidden|orientation"
            android:screenOrientation="portrait"
            android:label="@string/app_name" >

</activity>
        <activity android:name=".Products" >
</activity>
 <activity android:name=".ContactUs" >
</activity>
<activity android:name=".WebMapViewActivity" >
</activity>
<activity android:name=".WebViewActivity" >
</activity>
<activity android:name=".openAccuActivity" >
</activity>
<activity android:name=".BusesNearby" >
</activity>
<activity android:name=".openBiotransActivity" >
</activity>

<activity android:name=".openMultiLuActivity" >
</activity>
<activity android:name=".openThermoActivity" >
</activity>
<activity android:name=".openBiotrayActivity" >
</activity>
<activity android:name=".openBipolarActivity" >
</activity>
<activity android:name=".openEmboActivity" >
</activity>
<activity android:name=".openBioflexActivity" >
</activity>
<activity android:name=".openAxxessActivity" >
</activity>
<activity android:name=".openGazelleActivity" >
</activity>
<activity android:name=".openPowerlActivity" >
</activity>
<activity android:name=".AlertCaution" >
</activity>
<activity android:name=".BusRoutes" >
</activity>
<activity android:name=".AllBuses" >
</activity>
<activity android:name=".bus5route" >
</activity>
<activity android:name=".bus15route" >
</activity>
<activity android:name=".bus58route" >
</activity>
<activity android:name=".bus59route" >
</activity>
<activity android:name=".bus87route" >
            </activity>
               <activity android:name=".mrtMap" android:screenOrientation="portrait" >
               </activity>
               <meta-data    android:name="com.google.android.maps.v2.API_KEY"
    android:value="AIzaSyCFLLz6m3N1WEKNG6KnwvoQvMBTC4r9AzA"/>
          </application>
    </manifest>

还有我的 xml(我很确定我有正确的 API 密钥):

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

 <com.google.android.maps.MapView 
    android:id="@+id/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="***************"
    />

 </RelativeLayout>

和我的java代码:

 public class WebMapViewActivity extends MapActivity {

 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview);
        getActionBar();
        ActionBar actionBar = getActionBar();
        actionBar.setIcon(R.drawable.ic_menu_mapmode);
        actionBar.setTitle("Map");

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

 List<Overlay> mapOverlays = mapView.getOverlays();
 Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
 HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
 GeoPoint point = new GeoPoint(133339,-10390584);
 OverlayItem overlayitem = new OverlayItem(point, "Hello!","This is Biosensors Interventional Singapore !");

 itemizedoverlay.addOverlay(overlayitem);
 MapController mapController = mapView.getController();
 mapController.setCenter(point);

 mapOverlays.add(itemizedoverlay);
 }
 @Override
 protected boolean isRouteDisplayed()
 {
 return false;
 }

        }
4

2 回答 2

0

据我所知,您在这段代码中混合了 API v1 和 v2。

在您的布局中删除地图视图并添加:

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:name="com.google.android.gms.maps.MapFragment"/>

并扩展 Activity 而不是 MapActivity (或 FragmentActivity 如果您使用支持库)。

您可以在Maps API 页面查看更多信息

于 2013-03-15T08:41:22.200 回答
0

正如@DavidBriggs 所说,您正在混合来自 API V1 和 V2 的代码。

如果您想使用所有清单配置所显示的 Google Maps API V2,那么这是我写的关于如何添加的博客文章:

Google Map API V2 到您的应用程序。

于 2013-03-15T18:33:32.450 回答