[英]Android Google Map Application(map not showing up)
I know there have been a number of questions about this topic, but the answers have not been of use to me. 我知道有关此主题的问题很多,但是答案对我来说并没有用。 I have generated the key, added the fragment code, referred to the api key, but the screen is just grey as others have described with the lack of map problem.
我已经生成了密钥,并添加了片段代码(称为api密钥),但是屏幕只是灰色,就像其他人所描述的那样,没有地图问题。 My code is below.
我的代码如下。
activity_main.xml activity_main.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" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
Manifest File 清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flymap_awc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<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"/>
<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.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.example.flymap_awc.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyADeLIgFS42YPAPjUjODWj5nH4y_ZKVfBM"/>
</application>
</manifest>
Main Activity Java File 主要活动Java文件
> package com.example.flymap_awc;
>
> import android.app.Activity; import android.os.Bundle; import
> android.view.Menu;
>
> import com.google.android.gms.maps.CameraUpdateFactory; import
> com.google.android.gms.maps.GoogleMap; import
> com.google.android.gms.maps.MapFragment; import
> com.google.android.gms.maps.model.BitmapDescriptorFactory; import
> com.google.android.gms.maps.model.LatLng; import
> com.google.android.gms.maps.model.Marker; import
> com.google.android.gms.maps.model.MarkerOptions;
>
> public class MainActivity extends Activity { static final LatLng
> HAMBURG = new LatLng(53.558, 9.927); static final LatLng KIEL = new
> LatLng(53.551, 9.993); private GoogleMap map;
>
> @Override protected void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.activity_main);
> map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
> .getMap();
> Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
> .title("Hamburg"));
> Marker kiel = map.addMarker(new MarkerOptions()
> .position(KIEL)
> .title("Kiel")
> .snippet("Kiel is cool")
> .icon(BitmapDescriptorFactory
> .fromResource(R.drawable.ic_launcher)));
>
> // Move the camera instantly to hamburg with a zoom of 15.
> map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
>
> // Zoom in, animating the camera.
> map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); }
>
> @Override public boolean onCreateOptionsMenu(Menu menu) {
> getMenuInflater().inflate(R.menu.main, menu);
> return true; }
>
> }
The eventual goal is to use sensor listeners for rotation to move around the map, but first I just need to get the map to show up. 最终的目标是使用传感器侦听器旋转地图,但是首先我需要显示地图。 If anyone can help point out what I am doing wrong I will greatly appreciate it.
如果有人可以指出我在做什么错,我将不胜感激。 Thank You
谢谢
Please find the below consideration which may help you: 请找到以下考虑因素,可能会对您有所帮助:
1 . Have you turned on Google Maps Android API V2 in developer console? 2 . Are you using any new device where map has not been loaded yet, This might work as I had similar issue on a samsung device. This might not be a concrete step but you can try
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.