com.google.android.maps.v2.API_KEY

com.google.android.maps.v2.API_KEY,android,google-maps,android-fragments,Android,Google Maps,Android Fragments,我想让谷歌地图在安卓系统中使用,但我有一些问题 清单: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.odv" android:versionCode="1" android:versionName="1.0" > <us

我想让谷歌地图在安卓系统中使用,但我有一些问题

清单:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.odv"
    android:versionCode="1"
    android:versionName="1.0" >

<uses-permission android:name="YOUR_PACKAGE_NAME.permission.MAPS_RECEIVE"
 android:protectionLevel="signature"/>
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="your.package.name.permission.MAPS_RECEIVE" />
<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" />


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


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

        <!-- You must insert your own Google Maps for Android API v2 key in here. -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyCe29ye5iK83zx6rUBnCzulKCxf68nT-bs" />

        <activity
            android:name="com.example.odv.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>
    </application>

</manifest>
    <?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2012 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<!-- This can go anywhere in your layout (see other demos for some examples). 
<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"/>
-->
<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" />
    package com.example.odv;

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

public class MainActivity extends android.support.v4.app.FragmentActivity  {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
我想学安卓。我想我有编程的算法智能,但我不知道如何开始学习编程。我没有好的消息来源

我写了这段代码,但我看不到地图。我只能看到一个白色的屏幕,无法打开地图。我能为此做些什么


屏幕截图

您需要做的第一件事是,从获取API密钥,然后您需要在Android清单中使用该API密钥: 第一,使用适当的权限:

第二:使用功能

    android:glEsVersion="0x00020000"
    android:required="true" >
第三: 在元数据中:

android:name=“com.google.android.maps.v2.API\u KEY” android:value=“你的钥匙在这里”>


希望这有帮助:)

公共类MainActivity扩展了FragmentActivity{

private static final int GPS_ERRORDIALOG_REQUEST = 9001;
Button btn1;
EditText et1;
EditText et2;

GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (servicesOK()) {
        Toast.makeText(this, "Ready to map!!", Toast.LENGTH_LONG).show();
        setContentView(R.layout.testmap);

    } else {
        setContentView(R.layout.activitymain);

    }

    /*
     * et1 = (EditText)findViewById(R.id.edittext1); et2 =
     * (EditText)findViewById(R.id.edittext2); btn1 =
     * (Button)findViewById(R.id.button1);
     * 
     * btn1.setOnClickListener(this);
     */

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

/*
 * @Override public void onClick(View v) {
 * 
 * Object lat = et1; Object lon = et2;
 * 
 * Uri uri=Uri.parse("geo:"+lat.toString()+","+lon.toString()); Intent i=new
 * Intent(Intent.ACTION_VIEW, uri); startActivity(i); Log.d("The Location:",
 * lat.toString()+lon.toString());
 * 
 * 
 * }
 */
public boolean servicesOK() {

    int isAvailable = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);

    if (isAvailable == ConnectionResult.SUCCESS) {

        return true;

    } else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {

        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable,
                this, GPS_ERRORDIALOG_REQUEST);
        dialog.show();

    } else {

        Toast.makeText(this, "Cant connect!!", Toast.LENGTH_SHORT).show();

    }
    return false;
}
private static final int GPS_ERRORDIALOG_REQUEST = 9001;
Button btn1;
EditText et1;
EditText et2;

GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (servicesOK()) {
        Toast.makeText(this, "Ready to map!!", Toast.LENGTH_LONG).show();
        setContentView(R.layout.testmap);

    } else {
        setContentView(R.layout.activitymain);

    }

    /*
     * et1 = (EditText)findViewById(R.id.edittext1); et2 =
     * (EditText)findViewById(R.id.edittext2); btn1 =
     * (Button)findViewById(R.id.button1);
     * 
     * btn1.setOnClickListener(this);
     */

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

/*
 * @Override public void onClick(View v) {
 * 
 * Object lat = et1; Object lon = et2;
 * 
 * Uri uri=Uri.parse("geo:"+lat.toString()+","+lon.toString()); Intent i=new
 * Intent(Intent.ACTION_VIEW, uri); startActivity(i); Log.d("The Location:",
 * lat.toString()+lon.toString());
 * 
 * 
 * }
 */
public boolean servicesOK() {

    int isAvailable = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);

    if (isAvailable == ConnectionResult.SUCCESS) {

        return true;

    } else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {

        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable,
                this, GPS_ERRORDIALOG_REQUEST);
        dialog.show();

    } else {

        Toast.makeText(this, "Cant connect!!", Toast.LENGTH_SHORT).show();

    }
    return false;
}
}


另外,我只是在布局中添加了一个mapview,请不要忘记将API键放在清单中,因为如果没有它,映射将不会加载。要使用地图,请使用真实的设备,而不是模拟器:)

以下是我在测试应用程序中使用的地图的完整工作:


公共类MainActivity扩展了FragmentActivity{

private static final int GPS_ERRORDIALOG_REQUEST = 9001;
Button btn1;
EditText et1;
EditText et2;

GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (servicesOK()) {
        Toast.makeText(this, "Ready to map!!", Toast.LENGTH_LONG).show();
        setContentView(R.layout.testmap);

    } else {
        setContentView(R.layout.activitymain);

    }

    /*
     * et1 = (EditText)findViewById(R.id.edittext1); et2 =
     * (EditText)findViewById(R.id.edittext2); btn1 =
     * (Button)findViewById(R.id.button1);
     * 
     * btn1.setOnClickListener(this);
     */

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

/*
 * @Override public void onClick(View v) {
 * 
 * Object lat = et1; Object lon = et2;
 * 
 * Uri uri=Uri.parse("geo:"+lat.toString()+","+lon.toString()); Intent i=new
 * Intent(Intent.ACTION_VIEW, uri); startActivity(i); Log.d("The Location:",
 * lat.toString()+lon.toString());
 * 
 * 
 * }
 */
public boolean servicesOK() {

    int isAvailable = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);

    if (isAvailable == ConnectionResult.SUCCESS) {

        return true;

    } else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {

        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable,
                this, GPS_ERRORDIALOG_REQUEST);
        dialog.show();

    } else {

        Toast.makeText(this, "Cant connect!!", Toast.LENGTH_SHORT).show();

    }
    return false;
}
private static final int GPS_ERRORDIALOG_REQUEST = 9001;
Button btn1;
EditText et1;
EditText et2;

GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (servicesOK()) {
        Toast.makeText(this, "Ready to map!!", Toast.LENGTH_LONG).show();
        setContentView(R.layout.testmap);

    } else {
        setContentView(R.layout.activitymain);

    }

    /*
     * et1 = (EditText)findViewById(R.id.edittext1); et2 =
     * (EditText)findViewById(R.id.edittext2); btn1 =
     * (Button)findViewById(R.id.button1);
     * 
     * btn1.setOnClickListener(this);
     */

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

/*
 * @Override public void onClick(View v) {
 * 
 * Object lat = et1; Object lon = et2;
 * 
 * Uri uri=Uri.parse("geo:"+lat.toString()+","+lon.toString()); Intent i=new
 * Intent(Intent.ACTION_VIEW, uri); startActivity(i); Log.d("The Location:",
 * lat.toString()+lon.toString());
 * 
 * 
 * }
 */
public boolean servicesOK() {

    int isAvailable = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);

    if (isAvailable == ConnectionResult.SUCCESS) {

        return true;

    } else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {

        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable,
                this, GPS_ERRORDIALOG_REQUEST);
        dialog.show();

    } else {

        Toast.makeText(this, "Cant connect!!", Toast.LENGTH_SHORT).show();

    }
    return false;
}
}

///////////////////////////////////////////////////////////////////////////////////////

布局如下:

xmlns:maps="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
以下是Android清单:

package="com.mike.maps"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="18" />

<permission
    android:name="com.mike.maps.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.mike.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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-feature
    android:glEsVersion="0x00020000"
    android:required="true" >
</uses-feature>


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.mike.maps.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>
    <activity android:name="com.mike.maps.SecondActivity" >
    </activity>

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="Your key goes here" >
    </meta-data>
</application>
package=“com.mike.maps”
android:versionCode=“1”
android:versionName=“1.0”>

不再需要该许可证我想你会想编辑这个问题,以澄清问题,因为英语并不是这里唯一不好的东西-它是一个代码转储,没有显示任何研究,没有问题解释等(即,这里的实际问题是什么?是否存在编译器错误?异常?),其他人可能会进来修复你的语法/拼写等。请参考这张地图不要给出任何错误,只打开屏幕显示白色地图(你看不到地图,白色屏幕)这似乎是一个错误的按键错误。您是否已将您的debugkey签名添加到API控制台?权限为且在使用权限中:这是布局:我使用我的手机:(…SHA1:12:4A:F6:FE:9A:F6:2D:26:91:72:B1:3E:3B:34:A3:DF:A9:6F:13:30 SHA256:0C:78:D5:AD:5B:54:70:43:1B:6B:AB:96:8B:0B:04:57:74:E6:B3:78:B3:3E:2C:2D:61:49:6E:A2:53:62:99:DF签名算法名称:SHA256withRSA版本:3扩展名:351:D:false主客观标识符=29.14[KeyIdentifier[0000:69 88 12 01 60 76 8D 41 64 72 AB 05 CE 19 BF 31 i.`v.Adr.…1 0010:B8 BB 1E 61…a]]我使用Sha1作为键,并且(临界度=假)正常吗?坦克:)我尝试知道,但我正在尝试更好:)不要在电话中打开地图,目标:(你能给我发送完整的zip文件吗huseyin730@gmail.comPlay从来没有在google上使用过它。而且我也没有向google playa付费,所以这可能是一个关键错误吗