简体   繁体   English

使用Google Maps API android无法显示地图

[英]Map not displaying with Google Maps API android

I am installing the Google Maps API on my app. 我正在我的应用上安装Google Maps API。 I have everything running and can launch the Google Maps Activity, but the Map doesn't display. 我已经运行了一切,可以启动Google地图活动,但地图不会显示。 It just shows a grid that you can zoom in and out on. 它只显示一个可以放大和缩小的网格。

    package com.fotolife.app;

import android.os.Bundle;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class Map extends MapActivity {

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub
        super.onCreate(arg0);
        setContentView(R.layout.map);


    }


}

^ that is my Map.java 那是我的Map.java

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

    <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="I Took this out for security reasons, but it works."
/>

</LinearLayout>

^ Here is my map.xml 这是我的map.xml

Thanks for the help! 谢谢您的帮助!

If you are using Google Maps Android API v2 that's probably the reason why your project is not working. 如果您使用的是Google Maps Android API v2,那可能就是您的项目无效的原因。 To get this working you must go through the following steps: 要使其正常工作,您必须执行以下步骤:

Download and configure Google Play Services from SDK manager 从SDK管理器下载并配置Google Play服务

Google Play Services are part of the extras of Android's SDK. Google Play服务是Android SDK附加功能的一部分。 You can found it in the extras section. 您可以在附加部分找到它。

Add google play services lib JAR to your project build path 将google play services lib JAR添加到项目构建路径中

The lib JAR is installed in the path lib JAR安装在路径中

$ANDROIDSDK_HOME/extras/google/google_play_services/libproject/google-play-services_lib/libs

Get an API key using Google APIs Console 使用Google API控制台获取API密钥

You may generate a SHA1 fingerprint for debug purposes using your OS console by issuing the command: 您可以通过发出命令使用操作系统控制台生成SHA1指纹以进行调试:

$ keytool -list -v -keystore ~/.android/debug.keystore -storepass android

In the Google APIs Console go to API Access and in the right pane chose "Create new Android key...". 在Google API控制台中,转到API Access,然后在右侧窗格中选择“创建新的Android密钥...”。 Then put the SHA1 fingerprint in the textbox followed by a semicolon and your project's package name. 然后将SHA1指纹放在文本框中,后跟分号和项目的包名称。

Specify permission settings in your project's manifest file 在项目的清单文件中指定权限设置

Put the following inside manifest tag in your application manifest file (replace com.example with your project's package name): 将以下清单标记放在应用程序清单文件中(将com.example替换为项目的包名称):

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

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

Specify the API key generated from API Console in your project's manifest file 在项目的清单文件中指定从API控制台生成的API密钥

Put this as the last element before closing the application tag 在关闭应用程序标记之前将其作为最后一个元素

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="your api key goes here"/>

Add a map to your project 将地图添加到项目中

main.xml main.xml中

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

Main.java Main.java

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

public class Main extends Activity {

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

Run your application 运行您的应用程序

You should get everything working. 你应该把一切都搞定。

Hi this worked for me: 嗨这对我有用:

Remember where you got your api-key? 还记得你的api-key的位置吗? https://code.google.com/apis/console , go there and under Key for Android apps (with certificates) press edit allowed android apps. https://code.google.com/apis/console ,去那里和Key for Android应用程序(带证书)下按编辑允许的Android应用程序。

In my case the fingerprint refered to an old package in a different project so i just went to the cmd console and got my new fingerprint and typed in my current package name after it an BINGO. 在我的情况下,指纹指的是一个不同项目中的旧包,所以我只是去了cmd控制台并得到了我的新指纹,然后输入了我当前的包名称。

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

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