在Android的地图活动 [英] Map activity in android
问题描述
我创建的地图actvity.But对mapview.just显示空白块不显示地图。
有没有解决办法?
activity_main.xml中 -
<?XML版本=1.0编码=UTF-8&GT?;
<片段的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID /图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:名字=com.google.android.gms.maps.MapFragment/>
活动code -
包com.example.googlemap;
进口android.app.Activity;
进口android.os.Bundle;
公共类MainActivity延伸活动{@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
}
}
manifest文件 -
<采用-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =16/><许可
机器人:名字=com.example.googlemap.permission.MAPS_RECEIVE
安卓的ProtectionLevel =签名/>&所述;元数据
机器人:名字=com.google.android.maps.v2.AIzaSyDRv4Ul_9iPW-roHIsc8EuxKwkRN8jWivs
机器人:值=AIzaSyDRv4Ul_9iPW-roHIsc8EuxKwkRN8jWivs/><使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
<! -
以下两个权限不需要使用
谷歌地图Android版API V2,但建议。
- >
<使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/><用途特征
机器人:glEsVersion =0x00020000
机器人:要求=真/><应用
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名字=com.example.googlemap.MainActivity
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT; <使用库机器人:名字=com.google.android.maps/>
< /用途>
使用此之后
我得到以下异常 -
08-22 23:19:52.204:E / AndroidRuntime(584):致命异常:主要
08-22 23:19:52.204:E / AndroidRuntime(584):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.googlemap / com.example.googlemap.MainActivity}:android.view.InflateException:二进制XML文件行#7:错误充气类片段
旧图形页面已经去preciated。您不能创建为发布您的应用一个新的地图键。
您必须使用新的谷歌地图Android版API。以下是对文档和示例的链接。
<一href=\"https://developers.google.com/maps/documentation/android/start\">https://developers.google.com/maps/documentation/android/start
I have created map actvity.But its not showing map on mapview.just showing blank blocks. is there any solution?
activity_main.xml-
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
activity code-
package com.example.googlemap;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
manifest file-
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="com.example.googlemap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<meta-data
android:name="com.google.android.maps.v2.AIzaSyDRv4Ul_9iPW-roHIsc8EuxKwkRN8jWivs"
android:value="AIzaSyDRv4Ul_9iPW-roHIsc8EuxKwkRN8jWivs" />
<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" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<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" >
<activity
android:name="com.example.googlemap.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>
after using this i'm getting following exception-
08-22 23:19:52.204: E/AndroidRuntime(584): FATAL EXCEPTION: main
08-22 23:19:52.204: E/AndroidRuntime(584): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
Old MapView has been depreciated. You can't create a new Map key for publishing your app. You have to use new Google Maps for Android v2 API. Here's a link to the documents and example. https://developers.google.com/maps/documentation/android/start
这篇关于在Android的地图活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!