【问题标题】:App keep crashing, trying to have a Android Maps on my app应用程序不断崩溃,试图在我的应用程序上安装 Android 地图
【发布时间】:2015-09-15 14:35:08
【问题描述】:

我有一个正在制作并尝试使用 Google 地图的 android 应用程序。我添加了一个地图片段,并运行它以查看它的外观,但它一直在崩溃,我聚集了什么?

这是我的主要课程

package germanclub.blundenbusroute.co.za;

import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class Main extends Activity implements OnMapReadyCallback {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        MapFragment mapFragment =     (MapFragment)getFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        googleMap.addMarker(new MarkerOptions().position(new LatLng(-33.975449, 25.529952)).title("German Club Oktoberfest"));
    }
}

这是我的 Android 清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="germanclub.blundenbusroute.co.za"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="21"/>
    <application android:label="Oktoberfest Shuttle Service"     android:icon="@drawable/germanclubcrest"     android:theme="@android:style/Theme.Dialog">
        <activity android:name="Main"
                  android:label="Oktoberfest Shuttle Service">
            <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"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:id="@+id/lblwelcome" android:layout_gravity="center_horizontal" android:text="@string/welcome"
            android:textAlignment="center" android:layout_marginLeft="63dp"
            android:layout_alignParentTop="false" android:layout_centerHorizontal="true"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:id="@+id/lblpickuppoint"
            android:text="@string/pickuppoint" android:layout_marginLeft="0dp"
            android:layout_marginTop="42dp"
            android:layout_alignEnd="@+id/lblwelcome" android:layout_centerHorizontal="true" android:paddingTop="50dp"
            android:paddingBottom="15dp"/>
    <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_gravity="center_horizontal"
            android:orientation="horizontal" android:layout_marginLeft="0dp"
            android:layout_below="@+id/lblpickuppoint" android:layout_alignParentStart="false"
            android:layout_alignParentEnd="false"     android:layout_centerHorizontal="true" android:id="@+id/radioGroup">
        <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="NMMU"
                android:id="@+id/rdbNMMU" android:checked="true"/>
        <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="5 Ways Spar"
                android:id="@+id/rdb5Ways" android:checked="false"/>
        <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Sherwood Spar"
                android:id="@+id/rdbStadium" android:checked="false"/>
    </RadioGroup>
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="350dp"
              android:name="com.google.android.gms.maps.MapFragment"
              android:id="@+id/map"
              android:layout_centerHorizontal="true"/>
</RelativeLayout>

【问题讨论】:

  • 你能发布你的 logcat 吗?你注册你的地图了吗?我在清单上没有看到密钥。
  • 请张贴您的逻辑以便更清楚地了解您的问题,您的清单中也没有显示地图所需的权限
  • 您好,抱歉,我再次阅读了我的代码,抱歉犯了一个非常愚蠢的错误,即没有获取 google maps API 的密钥

标签: android google-maps google-play-services google-maps-api-2


【解决方案1】:

您错过了清单中的 Google Maps API 密钥和目标 Google Play 服务版本,不是吗?

参见例如https://developers.google.com/maps/documentation/android-api/config 学习如何设置地图。

【讨论】:

    【解决方案2】:

    我在清单中看不到密钥,

    但是,如果您使用的是 Android Studio,您可以创建一个新的已配置的谷歌地图项目活动。但记得注册你的地图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      • 2013-03-26
      相关资源
      最近更新 更多