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 查看应用程序的崩溃日志,以了解崩溃的具体原因。

    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗