简体   繁体   English

Android:如何加载谷歌地图

[英]Android:How to load google maps

I have tried this coding but I get only the grid lines and Google at the bottom in my output. 我已经尝试了这种编码,但是在输出的底部仅获得了网格线和Google。 Can anyone please help me for this problem. 谁能帮我解决这个问题。 I am getting unfortunately close when I use fragment, now I am using Map View in the main. 不幸的是,当我使用片段时,我越来越近了 ,现在我主要在使用Map View。
这是我得到的输出

XML 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 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;
    }
}

Manifest 表现

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

I want to know whether it is depricated. 我想知道它是否被描述。 If so how to solve it. 如果是这样,如何解决。
Can anyone explain what does depricated means? 有人可以解释什么是贬义吗?

Thanks in advance 提前致谢

You need to have these below things in your Manifest file 您需要在清单文件中包含以下内容

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

These lines should be inside <application> tag 这些行应位于<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" />

I suppose you to use MapFragment. 我想您要使用MapFragment。

The answers on this link can be useful for you. 此链接上的答案可能对您有用。 Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM