ssummeraw 2013-04-17 01:49 采纳率: 10%
浏览 863

在 launch 中的 Mapview 事例

我在做一个 mapview 事例,但是它在 activity launch 上崩溃。我创建的目标是在version 2.1上Google API ,在模拟器和真机上都崩溃,也不能重写isRouteDisplayed 方法,贴出代码:

package com.sandy.hellogooglemaps;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.maps.MapView;
public class HelloGoogleMaps extends Activity {
     /** Called when the activity is first created. */
    @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;
    }
}

manifest file:

<application android:icon="@drawable/icon" 
android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/app_name">
    <activity android:name=".HelloGoogleMaps"
              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>
<uses-permission android:name="android.permission.INTERNET" />

请求帮助!

  • 写回答

1条回答

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2022-12-21 14:10
    关注

    ChatGPT尝试为您解答,仅供参考
    看起来你的代码已经正确地设置了 MapView。但是,如果你的应用程序在启动时崩溃,这可能是由于地图 API 的问题导致的。


    为了使地图 API 工作,你需要在 AndroidManifest.xml 文件中提供 Google Maps API 密钥。要获取密钥,请访问 Google Maps API 控制台,然后按照说明创建一个新的 API 密钥。然后,将该密钥添加到 AndroidManifest.xml 文件的 application 元素中,如下所示:

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

    另外,请确保你已经在应用程序的 build.gradle 文件中包含了 Google Play 服务依赖项,如下所示:

    dependencies {
      implementation 'com.google.android.gms:play-services-maps:17.0.0'
    }
    

    如果你已经按照上述步骤进行操作,但仍然无法解决问题,你可以考虑从 Logcat 查看应用程序的崩溃日志,以了解崩溃的具体原因。

    评论

报告相同问题?

悬赏问题

  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?