谷歌Android MapView类的活动不开放Android中工作室 [英] Android Google Mapview Activity not opening in Android Studio
问题描述
我是新来的Android,我试图在Android手机上显示一个谷歌地图。我创建的API密钥,应该适用于任何Android应用程序(我没有给我的应用程序的任何特定的SHA)。我猜测不应该的问题。使用谷歌Android教程,我做的所有步骤,我得到了谷歌的水印左侧底部,但没有地图。我会后所使用的所有code。我曾尝试使用谷歌地图的活动出货的Android工作室1.2.1.1。我没有得到任何错误,但没有得到任何的地图
我使用的是MapFragment,因为它似乎比的MapView更加容易。
我还认为,开发者控制台,这个API - 我没有任何流量 - 会不会是API密钥不被使用,所以我的应用程序是没有得到的报告?我怀疑 - 我怎么能测试
?我想在这里遵循的步骤 - https://developers.google.com /地图/文档/安卓/地图
另一个相关的查询,我假设我可以创建多发的布局。我开始与一个空白的活动,作为我的闪屏,然后我试图去一个地图活动 - 我无法创建内部的Android Studio中的地图活动。我可以将其创建为通过向导的第一个活动,但不能作为第二个活动。我失去了一些东西?
任何帮助是pciated AP $ P $
的AndroidManifest.xml
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.nbapl.avapps.mapscreen>
<使用-权限的Android:名称=android.permission.INTERNET对/>
<使用-权限的Android:名称=android.permission.ACCESS_NETWORK_STATE/>
<使用-权限的Android:名称=android.permission.WRITE_EXTERNAL_STORAGE/>
<使用-权限的Android:名称=com.google.android.providers.gsf.permission.READ_GSERVICES/>
<! -
要使用的ACCESS_COARSE / FINE_LOCATION权限不需要
谷歌地图Android的API V2,但建议。
- >
<使用-权限的Android:名称=android.permission.ACCESS_COARSE_LOCATION/>
<使用-权限的Android:名称=android.permission.ACCESS_FINE_LOCATION/>
<用途特征
机器人:glEsVersion =0x00020000
机器人:要求=真/>
<应用
机器人:allowBackup =真
机器人:图标=@纹理映射/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
&所述;元数据
机器人:名称=com.google.android.gms.version
机器人:值=@整数/ google_play_services_version/>
&所述;元数据
机器人:名称=com.google.android.maps.v2.API_KEY
机器人:值=API_KEY/>
<活动
机器人:名称=。MapsActivity
机器人:标签=@字符串/ title_activity_maps>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
< /舱单>
我还用文件 - >项目结构 - >相关性 - APP->,发现谷歌播放服务也包括在内。
MapsActivity.java
包com.nbapl.avapps.mapscreen;
进口com.google.android.gms.maps *。
进口com.google.android.gms.maps.model *。
进口android.os.Bundle;
进口android.support.v4.app.FragmentActivity;
公共类MapsActivity扩展FragmentActivity实现OnMa preadyCallback {
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.map);
MapFragment mapFragment =(MapFragment)getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(本);
}
@覆盖
公共无效onMa pready(GoogleMap的地图){
map.addMarker(新MarkerOptions()
.position(新经纬度(0,0))
.title伪(这是中心));
}
}
下面是布局XML
< XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:ID =@ + ID /帧
机器人:后台=#ffe2ff0e
机器人:可点击=假
机器人:前景=#fffff9c5>
<片段的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID /图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:名称=com.google.android.gms.maps.MapFragment/>
< /的FrameLayout>
摇篮与依赖文件enetered在模块级build.gradle
应用插件:com.android.application
安卓{
compileSdkVersion 22
buildToolsVersion23.0.0 RC2
defaultConfig {
的applicationIDcom.nbapl.avapps.mapscreen
的minSdkVersion 15
targetSdkVersion 22
版本code 1
VERSIONNAME1.0
}
buildTypes {
推出 {
minifyEnabled假
proguardFiles getDefaultProguardFile('ProGuard的-android.txt'),'proguard-rules.pro
}
}
}
依赖{
编译文件树(导演:库,包括:['的* .jar'])
编译com.google.android.gms:播放服务:7.5.0
编译com.android.support:appcompat-v7:22.2.0
}
您的活动创建布局,但你需要一些额外的code到真正开始了图:
在MapsActivity.java:
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_maps);
MapFragment mapFragment =(MapFragment)getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(本);
}
此外,您的活动应该实现OnMa preadyCallback更多的映射逻辑。查看文档, https://developers.google.com/maps/documentation/android/一>
I am new to Android and am trying to display a Google Map on an Android Phone. I created the API Key that should work for any Android App ( I did not give any specific SHA for my app). I am guessing that should not matter. Using the Google Android Tutorials, I am doing all the steps, I get the google watermark on the left bottom, but no map. I will post all the code being used. I have tried to use the Google Maps Activity shipped in Android Studio 1.2.1.1. I don't get any errors, but don't get the map either.
I am using a MapFragment as it seems to be easier than the MapView.
I also viewed the developers console for this API - I dont have any traffic - could it be that the API key is not being used and so my app is not getting the report? I suspect that - how can I test that?
I am trying to follow the steps here - https://developers.google.com/maps/documentation/android/map
Another related query is, I am assuming I can create mutiple layouts. I started with a Blank Activity that acts as my Splash screen, then I am trying to go to a Map Activity - I am not able to create a Map Activity inside Android Studio. I can create it as the first activity through the wizard, but not as a second activity. Am I missing something?
Any help is appreciated
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nbapl.avapps.mapscreen" >
<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 ACCESS_COARSE/FINE_LOCATION 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="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I have also used File->Project Structure ->Dependencies - App-> and found that Google Play Services is included.
MapsActivity.java
package com.nbapl.avapps.mapscreen;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("This is the center"));
}
}
Here is the Layout xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame"
android:background="#ffe2ff0e"
android:clickable="false"
android:foreground="#fffff9c5">
<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" />
</FrameLayout>
Gradle file with dependencies enetered at the module level build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
defaultConfig {
applicationId "com.nbapl.avapps.mapscreen"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.android.support:appcompat-v7:22.2.0'
}
Your activity creates the layout, but you need some additional code to actually start the map:
In MapsActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
Also, your activity should implement OnMapReadyCallback for more map logic. See the documentation at https://developers.google.com/maps/documentation/android/
这篇关于谷歌Android MapView类的活动不开放Android中工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!