简体   繁体   English

如何在Android Apk应用程序上显示Google地图?

[英]How to show the google maps on Android Apk Application?

I'm trying more than 2 days to get google maps work in android app. 我正在尝试超过2天的时间才能在Android应用程序中使用Google Maps。 At first when I tried to do this with the Emulator, it didn't show the map only a Grid. 最初,当我尝试使用仿真器执行此操作时,它并没有仅将地图显示为网格。 So, later on I tried to Export the App to Apk and to install it directly into my Galaxy note 2. In the phone it showed the same = Grid with Minus and Plus at the bottom.(Same as the Emulator did). 因此,稍后我尝试将App导出到Apk,并将其直接安装到我的Galaxy note 2中。在手机中,它的底部显示了相同的=网格,负号和加号。(与模拟器相同)。 Now I thought that it may be my API Key (with Google maps v2 turned on), but I followed the Instructions carefully and did it properly. 现在,我认为这可能是我的API密钥(已启用Google Maps v2),但是我仔细地按照了说明进行操作并正确执行了操作。 So, At the Bottom Line, I have the Libraries needed (android-support-v4.jar+google-play-services.jar), and nothing works, the map doesn't appear. 因此,在最底线,我需要使用库(android-support-v4.jar + google-play-services.jar),但没有任何效果,地图不会出现。

Does someone know how to solve this issue ? 有人知道如何解决这个问题吗?

My MainActivity.java : 我的MainActivity.java:

package com.example.map;

import android.view.Menu;

import android.os.Bundle;
import android.app.Activity;



public class MainActivity extends Activity 

{ {

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.main,menu);
        return true;

} }

My activity_main.xml layout is: 我的activity_main.xml布局是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >



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

And my Manifest.xml is: 我的Manifest.xml是:

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

<uses-permission android:name="android.permission.INTERNET"/>
<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-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<permission
android:name="com.example.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >


<activity
android:name="com.example.map.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" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD5dqdfd0TLVBzugqqJ_-4OKqWs_MojR4Y"/>
</application>

</manifest>

Google api console-> Services has two choice. Google api控制台->服务有两种选择。 They are closed. 他们是封闭的。

1-Google Maps Android API v2 2-Google Maps API v2 1-Google Maps Android API v2 2-Google Maps API v2

Check choice 1(Google Maps Android API v2). 选中选项1(Google Maps Android API v2)。

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

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