Java-Google Maps v2简单应用程序无法正常工作

Java-Google Maps v2简单应用程序无法正常工作,第1张

概述我正在关注this教程.这是我所有相关的文件:activity_main.xml中<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apkes/android"android:layout_width="fill_parent"andr

我正在关注this教程.这是我所有相关的文件:
activity_main.xml中

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent" >    <fragment        androID:ID="@+ID/map"        androID:name="com.Google.androID.gms.maps.MapFragment"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"/></relativeLayout>

MainActivity.java

package org.barisakkurt.Googlemapsv2;import androID.app.Fragment;import androID.os.Bundle;import androID.support.v4.app.FragmentActivity;import androID.Widget.Toast;import com.Google.androID.gms.maps.GoogleMap;import com.Google.androID.gms.maps.SupportMapFragment;public class MainActivity extends FragmentActivity {    // Google Map    private GoogleMap GoogleMap;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        try {            // Loading map            initilizeMap();        } catch (Exception e) {        }    }    /**     * function to load map. If map is not created it will create it for you     * */    private voID initilizeMap() {        if (GoogleMap == null) {            GoogleMap = ((SupportMapFragment)  getSupportFragmentManager().findFragmentByID(R.ID.map)).getMap();            // check if map is created successfully or not            if (GoogleMap == null) {                Toast.makeText(getApplicationContext(),                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)                        .show();            }        }    }    @OverrIDe    protected voID onResume() {        super.onResume();        initilizeMap();    }}

AndroIDManifest.xml中

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="org.barisakkurt.Googlemapsv2"    androID:versionCode="1"    androID:versionname="1.0" >    <uses-sdk        androID:minSdkVersion="8"        androID:targetSdkVersion="18" />    <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" />    <application        androID:allowBackup="true"        androID:icon="@drawable/ic_launcher"        androID:label="@string/app_name"        androID:theme="@style/Apptheme" >        <activity            androID:name="org.barisakkurt.Googlemapsv2.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>        <Meta-data            androID:name="com.Google.androID.maps.v2.API_KEY"            androID:value="AIzaSyAC7y4bP-MjeJljm6Fr9Og1FKxNe9ZiFkY" />    </application></manifest>

我完成了教程,直到标题为“放置标记”为止.但是我收到以下错误.

Caused by: @[email protected]: The Meta-data tag in your app's AndroIDManifest.xml does not have the right value.  Expected 4030500 but found 0.  You must have the following declaration within the <application> element:     <Meta-data androID:name="com.Google.androID.gms.version" androID:value="@integer/Google_play_services_version" />

如果我将清单文件写入以下行:

<Meta-data            androID:name="com.Google.androID.gms.version"            androID:value="4030500" />

这次我得到这个错误:

Caused by: @[email protected]: API key not found.  Check that <Meta-data androID:name="com.Google.androID.maps.v2.API_KEY" androID:value="your API key"/> is in the <application> element of AndroIDManifest.xml

androID在跟我开玩笑吗?为什么代码崩溃?我该怎么办才能运行该死的简单代码?为什么它在本教程中而不在我的机器上可以工作.这让我很烦.

(顺便说一句,我将windows 7与实际设备Nexus 7结合使用,并且我复制了version.xml并尝试了以下元数据

<Meta-data            androID:name="com.Google.androID.gms.version"            androID:value="@integer/Google_play_services_version" />

再次没有工作.最后,我当然搜索了SO,谷歌看了流行的教程)请帮助我.

解决方法:

您需要具有两个元数据字段.一般而言,其中一项是Google Play服务所必需的,第二项是使用地图所必需的.

您应该在[androID-sdk] /extras/Google/Google_play_services/samples/maps/AndroIDManifest.xml中的示例应用程序中的示例代码段

  <application    androID:icon="@drawable/ic_launcher"    androID:label="@string/demo_Title"    androID:harDWareAccelerated="true">    <!-- ** You need to replace the key below with your own key. **         The example key below will not be accepted because it is not linked to the         certificate which you will use to sign this application.         See: https://developers.Google.com/maps/documentation/androID/start         for instructions on how to get your own key. -->    <Meta-data            androID:name="com.Google.androID.maps.v2.API_KEY"            androID:value="AIzaSyCvGBr5in13NK2yYBR7lhXTtnxj3mrXQy4" />    <Meta-data            androID:name="com.Google.androID.gms.version"            androID:value="@integer/Google_play_services_version" />
总结

以上是内存溢出为你收集整理的Java-Google Maps v2简单应用程序无法正常工作全部内容,希望文章能够帮你解决Java-Google Maps v2简单应用程序无法正常工作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1092992.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存