【问题标题】:error: in google MapView layout错误:在谷歌 MapView 布局中
【发布时间】:2013-09-01 05:48:30
【问题描述】:

我是 android 谷歌地图的新手,我按照一些教程开始,我遇到了错误。我无法在模拟器(三星银河 2)上看到 google 地图, 我写了下面所有的代码,请帮助我解决错误。

Manifest.xml

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

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

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

</manifest>

MainActivity.java

package com.examp.onemap;

import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class MainActivity extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);   
    MapView mapView = (MapView) findViewById(R.id.mapView);
    mapView.setBuiltInZoomControls(true);
}

@Override
protected boolean isRouteDisplayed() {
    return false;
}

}

我从`https://code.google.com/apis/console/生成密钥

ma​​in.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="AIzaSyDXwNWYXS9Lz9d-bJlodc1GELulHsalkT0"/>

【问题讨论】:

    标签: java android google-maps google-maps-api-3 google-api


    【解决方案1】:

    首先,您要混合使用两种 Google Maps API。您正在尝试使用看起来像 API V2 密钥的 Google Maps API V1 对象和代码。这永远不会奏效。因此,您首先需要将代码更改为 API V2 代码。你可以按照我写的这个教程来做:

    Google Maps API V2

    现在,即使您将代码更改为 API V2 代码,这仍然无法在模拟器上运行,因为如果不先安装 Google Play Services API,您将无法在模拟器上运行 Google Maps API V2。

    【讨论】:

    • 感谢您的重播。我安装了谷歌播放服务,但我仍然在片段中的 main.xml @xmlns:map="schemas.android.com/apk/res-auto" 中收到错误。
    • 如果在xml文件的fragment组件上不使用任何其他map属性,可以尝试去掉这一行。在真机上查看应用会发生什么?
    • 我删除了这条线。我在 Galaxy s2 中执行了这个应用程序。我有一个带有缩放功能的白色背景视图,但我看不到地图..:(
    • 您没有按照我提供的教程进行操作,并且您在 xml 文件和 java 文件中使用了错误的对象。使用我提供的教程来使用 Google Maps API V2。
    • 我再次从 [link]blog-emildesign.rhcloud.com/?p=403 和 [link]blog-emildesign.rhcloud.com/?p=435 学习了您的教程。我仍然面临 main.xml 错误的问题。我在 Windows 8 上使用 ADT 包。我不知道该怎么做。
    【解决方案2】:

    如果您已将其更改为 V2,这可以帮助您:

    Running Google Maps v2 on the Android emulator

    希望 ;)

    【讨论】:

      【解决方案3】:

      编码是谷歌地图 v1。切换到谷歌地图 v2。

      文档在这里

      https://developers.google.com/maps/documentation/android/start

      教程是

      http://www.vogella.com/articles/AndroidGoogleMaps/article.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-12
        • 1970-01-01
        • 1970-01-01
        • 2016-10-23
        • 2018-10-13
        • 1970-01-01
        • 2014-05-18
        相关资源
        最近更新 更多