Android:如何加载谷歌地图

时间:2014-09-30 06:37:47

标签: java android maps

我已尝试过这种编码,但我的输出中只有网格线和Google底部。任何人都可以帮我解决这个问题。当我使用片段时,我得到不幸关闭,现在我在主要使用Map View this is the output I got

XML

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <com.google.android.maps.MapView 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:apiKey="AIzaSyDpO3gdeRI_KgD1-6iTpxNlMy5Btj_pWFw" 
        android:clickable="true" 
        android:enabled="true" 
        android:id="@+id/myGMap"/> 
</LinearLayout>

JAVA

public class MainActivity extends MapActivity {

    MyLocationOverlay myLocationOverlay;

    MapView         myMapView       = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        // extract MapView from layout

            myMapView = (MapView) findViewById(R.id.myGMap);

            myMapView.setBuiltInZoomControls(true);



            // create an overlay that shows our current location

            myLocationOverlay = new MyLocationOverlay(this, myMapView);



            // add this overlay to the MapView and refresh it

            myMapView.getOverlays().add(myLocationOverlay);

            myMapView.postInvalidate();

    }

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

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.map2"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>

    <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=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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


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

    </application>

</manifest>

我想知道它是否被删除。如果是这样,如何解决它 任何人都可以解释 depricated 的含义吗?

提前致谢

2 个答案:

答案 0 :(得分:0)

您需要在清单文件中包含以下内容

<permission
        android:name="com.example.map2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.map2.permission.MAPS_RECEIVE" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Required to show current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- Required OpenGL ES 2.0. for Maps V2 -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

这些行应位于<application>标记

<!-- Goolge API Key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR API KEY" />

        <meta-data android:name="com.google.android.gms.version" android:value="4030500" />

答案 1 :(得分:0)

我想你要使用MapFragment。

this link上的答案对您有用。祝你好运。