android映射第一个程序

时间:2012-11-20 21:04:17

标签: android google-maps mobile

我正在阅读有关移动地图应用程序的Google教程。 我设法在Android虚拟电话中编译和运行我的应用程序:

5.4 FWVGA(480x854:mdpi)。

当我真正在手机中启动应用程序时,我只会得到一张背景平方的空白地图(如几何纸)。

我的感觉是这里出了点问题:

RES /布局/ activity_main.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"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

</RelativeLayout>

RES /布局/ main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<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="blablabla"
/>

的AndroidManifest.xml:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <uses-library android:name="com.google.android.maps"/>
        <activity
            android:name=".HelloGoogleMaps" android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
       </activity>
    </application>
</manifest>

所以要明确的是,如何让我的应用程序连接到互联网并加载磁贴?

感谢

jenia

3 个答案:

答案 0 :(得分:2)

除了检查清单文件中是否已授予Internet权限(这是我开始开发新应用程序时忘记的内容)之外,您在MapView对象的apiKey属性中使用的密钥是专门创建的用于调试目的?如果不是这种情况,您将无法看到图块,尽管您仍然可以与MapView进行交互。

答案 1 :(得分:1)

假设您在项目中引用了Google API但尚未获得API密钥 - 请转到here并使用{{3}指导您准备好使用您的项目!

答案 2 :(得分:0)

这个链接是一个完整的解决方案:

(PT-BR) http://developerai.blogspot.com.br/2012/07/android-development-google-maps.html

别忘了

 <uses-library android:name="com.google.android.maps" />

如果您是高级开发人员并喜欢更好的应用,请了解:

https://github.com/cyrilmottier/Polaris