gpt4 book ai didi

android - 在实际设备上运行谷歌地图

转载 作者:行者123 更新时间:2023-11-30 03:17:04 25 4
gpt4 key购买 nike

我试图在实际设备中运行谷歌地图有 android 版本 4.0.3 ICE sandwitch,我阅读了很多教程,每个设置都很好,比如:在 SDK 管理器中安装 google play 服务。在我的应用程序中导入 google play 服务库。获取谷歌地图 API key 。

list 文件代码如下所示:

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

<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="15" />

<permission
android:name="com.example.google_map_application.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>

<uses-permission android:name="com.example.google_map_application.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCoIsr6NxAH_J3NLtkh5YSxQGZAq1gvWW8" />
<activity
android:name="com.example.google_map_application.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>
</application>

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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

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

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />

主要 Activity 代码为:

package com.example.google_map_application;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends Activity{
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097);
Marker ciu = mMap.addMarker(new MarkerOptions() .position(CIU).title("My Office"));


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;

}

此错误不断出现:

java.lang.RuntimeException:无法启动 Activity ComponentInfo{com.example.google_map_application/com.example.google_map_application.MainActivity}:android.view.InflateException:二进制 XML 文件第 16 行:膨胀类 fragment 时出错。

最佳答案

尝试将 Target SDK 更改为类似于您的 Google Play 服务库版本的内容,例如:

<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="17" />

关于android - 在实际设备上运行谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19877278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com