地图与谷歌地图API的Andr​​oid显示 [英] Map not displaying with Google Maps API android

查看:111
本文介绍了地图与谷歌地图API的Andr​​oid显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序安装谷歌地图API。我把一切都运行,并且可以启动谷歌地图的活动,但地图不显示。它只是显示一个网格,你可以放大和缩小。

 包com.fotolife.app;进口android.os.Bundle;进口com.google.android.maps.MapActivity;
进口com.google.android.maps.MapView;公共类地图扩展MapActivity {    @覆盖
    保护布尔isRouteDisplayed(){
        // TODO自动生成方法存根
        返回false;
    }    @覆盖
    保护无效的onCreate(捆绑为arg0){
        // TODO自动生成方法存根
        super.onCreate(为arg0);
        的setContentView(R.layout.map);
    }
}

^这是我的Map.java

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>    < com.google.android.maps.MapView
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID /图形页面
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:可点击=真
    机器人:apiKey =我把这个出于安全考虑,但它的作品。
/>< / LinearLayout中>

^这是我map.xml

感谢您的帮助!


解决方案

如果您使用的是谷歌Android的地图API V2这可能就是你的项目是不工作的原因。为了得到这个工作,你必须经过以下步骤:

下载和配置谷歌来自SDK管理器播放服务

谷歌播放服务是Android的SDK的额外的一部分。你可以发现它在额外部分。

加入谷歌发挥服务的lib JAR到项目的构建路径

的lib中的JAR安装在路径

<$p$p><$c$c>$ANDROIDSDK_HOME/extras/google/google_play_services/libproject/google-play-services_lib/libs

获取使用谷歌的API控制台的API密钥

您可以通过发出命令生成使用OS控制台调试目的SHA1指纹:

  $的keytool -list -v -keystore〜/ .android / debug.keystore -storepass机器人

在谷歌API的控制台去API访问,并在右侧窗格中选择创建新的Andr​​oid密钥...。然后把SHA1指纹在文本框中后跟一个分号和项目的包名。

在项目的清单文件中的指定权限设置

将下面的清单内标签在你的应用程序清单文件(替换项目的包名称com。示例):

 &LT;允许机器人:名字=com.example.permission.MAPS_RECEIVE安卓的ProtectionLevel =签名/&GT;
  &LT;使用许可权的android:NAME =com.example.permission.MAPS_RECEIVE/&GT;
  &LT;采用-SDK安卓的minSdkVersion =8机器人:targetSdkVersion =17/&GT;
  &LT;使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/&GT;
  &LT;使用许可权的android:NAME =android.permission.INTERNET对/&GT;
  &LT;使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/&GT;
  &LT;使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/&GT;
  &LT;使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/&GT;
  &LT;使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/&GT;  &LT;! - Maps API需要OpenGL ES 2.0的。 - &GT;
  &LT;使用特征的android:glEsVersion =0x00020000机器人:所需=真/&GT;

指定项目的manifest文件从API控制台生成的API密钥

在关闭应用程序标记之前将这个作为最后一个元素

 &LT;元数据
        机器人:名字=com.google.android.maps.v2.API_KEY
        机器人:价值=你的API密钥放在这里/&GT;

地图添加到您的项目

main.xml中

 &LT;片段的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:ID =@ + ID /图
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent
  类=com.google.android.gms.maps.SupportMapFragment/&GT;

Main.java

 进口android.app.Activity;
进口android.os.Bundle;公共类主要活动扩展{    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
    }
}

运行应用程序

您应该使一切工作正常。

I am installing the Google Maps API on my app. I have everything running and can launch the Google Maps Activity, but the Map doesn't display. 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

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

Thanks for the help!

解决方案

If you are using Google Maps Android API v2 that's probably the reason why your project is not working. To get this working you must go through the following steps:

Download and configure Google Play Services from SDK manager

Google Play Services are part of the extras of Android's SDK. You can found it in the extras section.

Add google play services lib JAR to your project build path

The lib JAR is installed in the path

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

Get an API key using Google APIs Console

You may generate a SHA1 fingerprint for debug purposes using your OS console by issuing the command:

$ 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...". Then put the SHA1 fingerprint in the textbox followed by a semicolon and your project's package name.

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):

  <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

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

<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

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.

这篇关于地图与谷歌地图API的Andr​​oid显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆