谷歌地图API V2地图不可见 [英] Google Map API V2 Map Is Not Visible

查看:120
本文介绍了谷歌地图API V2地图不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了很多事情来解决它,但是,我仍然无法看到地图。我敢肯定,我的 ApiKey 真正谷歌地图Android的API V2 激活。

如果我尝试在模拟器,它崩溃。但是,如果我尝试它的作品在真实设备上,但我不能看地图,只有空白平原。

我的LogCat中

  10-04 21:46:35.712:W / GooglePlayServicesUtil(1540):谷歌Play商店丢失。
10-04 21:46:35.722:W / GooglePlayServicesUtil(1540):谷歌Play商店丢失。
10-04 21:46:35.763:W / GooglePlayServicesUtil(1540):谷歌Play商店丢失。
10-04 21:46:35.822:W / GooglePlayServicesUtil(1540):谷歌Play商店丢失。
10-04 21:46:35.822:W / GooglePlayServicesUtil(1540):谷歌Play商店丢失。
10-04 21:46:35.902:W / GooglePlayServicesUtil(1540):谷歌Play商店丢失。
10-04 21:46:35.902:D / AndroidRuntime(1540):关闭VM
10-04 21:46:35.902:W / dalvikvm(1540):主题ID = 1:螺纹未捕获的异常退出(组= 0x40a71930)
10-04 21:46:35.922:E / AndroidRuntime(1540年):致命异常:主要
10-04 21:46:35.922:E / AndroidRuntime(1540):了java.lang.RuntimeException:无法启动活动ComponentInfo{info.tekguc.touregsys.googlemapsandroidv2/info.tekguc.touregsys.googlemapsandroidv2.MainActivity}:显示java.lang.NullPointerException
10-04 21:46:35.922:E / AndroidRuntime(1540年):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在android.os.Handler.dispatchMessage(Handler.java:99)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在android.os.Looper.loop(Looper.java:137)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在android.app.ActivityThread.main(ActivityThread.java:5041)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在java.lang.reflect.Method.invokeNative(本机方法)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在java.lang.reflect.Method.invoke(Method.java:511)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在dalvik.system.NativeStart.main(本机方法)
10-04 21:46:35.922:E / AndroidRuntime(1540):因:显示java.lang.NullPointerException
10-04 21:46:35.922:E / AndroidRuntime(1540年):在info.tekguc.touregsys.googlemapsandroidv2.MainActivity.onCreate(MainActivity.java:18)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在android.app.Activity.performCreate(Activity.java:5104)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-04 21:46:35.922:E / AndroidRuntime(1540年):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
10-04 21:46:35.922:E / AndroidRuntime(1540):11 ...更多
10-04 21:46:39.262:I /流程(1540年):发送信号。 PID:1540 SIG:9

activity_main.xml中

 < RelativeLayout的
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:paddingBottom会=@扪/ activity_vertical_margin
机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
机器人:paddingTop =@扪/ activity_vertical_margin
工具:上下文=MainActivity。>
<的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/参考hello world/>
<片段
        机器人:ID =@ + ID /图
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
类=com.google.android.gms.maps.MapFragment/>
< / RelativeLayout的>

MainActivity.java

 包info.tekguc.touregsys.googlemapsandroidv2;进口android.os.Bundle;
进口android.app.Activity;
进口android.view.Menu;
进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.MapFragment;
进口com.google.android.gms.maps.model.LatLng;
进口com.google.android.gms.maps.model.Marker;
进口com.google.android.gms.maps.model.MarkerOptions;
公共类MainActivity延伸活动{
私人GoogleMap的MMAP;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
MMAP =((MapFragment)getFragmentManager()findFragmentById(R.id.map)。)的GetMap();
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
最后的经纬度CIU =新的经纬度(35.21843892856462,33.41662287712097);
标记CIU = mMap.addMarker(新的MarkerOptions()
.POSITION(CIU).title伪(我的办公室));
}
@覆盖
公共布尔onCreateOptionsMenu(菜单菜单){
//充气菜单;如果是present这增加了项目操作栏。
。getMenuInflater()膨胀(R.menu.main,菜单);
返回true; }}

清单

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=info.tekguc.touregsys.googlemapsandroidv2
    安卓版code =1
    机器人:=的versionName1.0>        <许可
        机器人:名字=com.example.androidmapsv2.permission.MAPS_RECEIVE
        安卓的ProtectionLevel =签名>< /许可>
    <使用许可权
        机器人:名字=com.example.androidmapsv2.permission.MAPS_RECEIVE/>
    <使用许可权
        机器人:名字=com.google.android.providers.gsf.permission.READ_GSERVICES/>
    <使用许可权
        机器人:名字=android.permission.INTERNET对/>
    <使用许可权
        机器人:名字=android.permission.WRITE_EXTERNAL_STORAG​​E/>
    <使用许可权
        机器人:名字=android.permission.ACCESS_COARSE_LOCATION/>
    <使用许可权
        机器人:名字=android.permission.ACCESS_FINE_LOCATION/>    <用途特征
        机器人:glEsVersion =0x00020000
        机器人:要求=真/>    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
          &所述;元数据
            机器人:名字=com.google.android.maps.v2.API_KEY
            机器人:值=我在这里写下我的API密钥/>
        <活动
            机器人:名字=info.tekguc.touregsys.googlemapsandroidv2.MainActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
    < /用途>< /清单>


解决方案

如果该API密钥仅用于调试目的产生,确保设备执行应用程序的调试版本。

I tried a lot of things which to fix it but, I still can't see the map. I'm sure that my ApiKey is true and Google Maps Android Api v2 is active.

If I try it on emulator, it crashes. But if I try it on a real device it works, but i can't see the map, only blank plain.

My LogCat

10-04 21:46:35.712: W/GooglePlayServicesUtil(1540): Google Play Store is missing.
10-04 21:46:35.722: W/GooglePlayServicesUtil(1540): Google Play Store is missing.
10-04 21:46:35.763: W/GooglePlayServicesUtil(1540): Google Play Store is missing.
10-04 21:46:35.822: W/GooglePlayServicesUtil(1540): Google Play Store is missing.
10-04 21:46:35.822: W/GooglePlayServicesUtil(1540): Google Play Store is missing.
10-04 21:46:35.902: W/GooglePlayServicesUtil(1540): Google Play Store is missing.
10-04 21:46:35.902: D/AndroidRuntime(1540): Shutting down VM
10-04 21:46:35.902: W/dalvikvm(1540): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
10-04 21:46:35.922: E/AndroidRuntime(1540): FATAL EXCEPTION: main
10-04 21:46:35.922: E/AndroidRuntime(1540): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.tekguc.touregsys.googlemapsandroidv2/info.tekguc.touregsys.googlemapsandroidv2.MainActivity}: java.lang.NullPointerException
10-04 21:46:35.922: E/AndroidRuntime(1540):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at android.os.Looper.loop(Looper.java:137)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at android.app.ActivityThread.main(ActivityThread.java:5041)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at java.lang.reflect.Method.invokeNative(Native Method)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at java.lang.reflect.Method.invoke(Method.java:511)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at dalvik.system.NativeStart.main(Native Method)
10-04 21:46:35.922: E/AndroidRuntime(1540): Caused by: java.lang.NullPointerException
10-04 21:46:35.922: E/AndroidRuntime(1540):     at info.tekguc.touregsys.googlemapsandroidv2.MainActivity.onCreate(MainActivity.java:18)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at android.app.Activity.performCreate(Activity.java:5104)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-04 21:46:35.922: E/AndroidRuntime(1540):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
10-04 21:46:35.922: E/AndroidRuntime(1540):     ... 11 more
10-04 21:46:39.262: I/Process(1540): Sending signal. PID: 1540 SIG: 9

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" >
<TextView        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="@string/hello_world" />
<fragment
        android:id="@+id/map"     
        android:layout_width="match_parent"        
        android:layout_height="match_parent"        
class="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>

MainActivity.java

package info.tekguc.touregsys.googlemapsandroidv2;

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
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; 
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;     } } 

Manifest

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

        <permission
        android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"></permission>
    <uses-permission
        android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/>
    <uses-permission
        android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission
        android:name="android.permission.INTERNET"/>
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <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="i wrote my api key here"/>
        <activity
            android:name="info.tekguc.touregsys.googlemapsandroidv2.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>

</manifest>

解决方案

If the API Key is generated for debugging purposes only, ensure that your device executes the debug version of the application.

这篇关于谷歌地图API V2地图不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆