简体   繁体   English

如何在Android上使用Google Maps API V2

[英]How to use google maps API V2 on Android

I did the following operation: -Download Google play service for Android SDK 我执行了以下操作:-下载适用于Android SDK的Google Play服务

-Import google-play-services_lib from SDK folder -从SDK文件夹导入google-play-services_lib

-Add this like lib on my app -在我的应用程序中像lib这样添加

-Take my SHA1 code form ecplipse windows/preferences/android/build -以我的SHA1代码形式ecplipse Windows / preferences / android / build

-Create new project on Google APIs Console; -在Google API控制台上创建新项目;

-Take my API code with: SHA1 code and project's pakage name -使用以下代码获取我的API代码:SHA1代码和项目的包装名称

-Add permission on manifest: -在清单上添加权限:

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

        <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true" />

and

    <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="mykey" />

on application tag -create new xml file with this code: 在应用程序标签上-使用以下代码创建新的xml文件:

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

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

and new activity with this(it's not in main activity): 以及与此相关的新活动(不在主要活动中):

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;

    public class Map extends FragmentActivity {

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

    }

    }

Where is the problem? 问题出在哪儿?

First of all I would ask what is the problem you have?:) we are not telepats.. From what I can see here, I would say you are missing another 'meta' attribute for the play services, but this would be reported into logcat: 首先,我想问您有什么问题?:)我们不是电话传讯者。从这里我可以看到,我想说您缺少播放服务的另一个“元”属性,但是这将被报告为logcat的:

<meta-data android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version" />

So whats the actual problem? 那么实际的问题是什么? Is it crashing, just blank map, whats the logcat output? 它崩溃了吗,只是空白地图,logcat的输出是什么?

Also some people try to add play services .jar file instead of referencing the project. 也有人尝试添加播放服务.jar文件而不是引用项目。 This leads to crash as well 这也导致崩溃

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

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