简体   繁体   中英

Google Map API V2 Map Is Not Visible

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>

如果仅出于调试目的而生成API密钥,请确保您的设备执行应用程序的调试版本。

You are using Activity (not FragmentActivity) with SupportMapFragment, and I doubt that will work. Which version of android target are you using? before android 4 you must inckude compatibility library too. If you are in debug you have to generate key from debug keystore signature that is the default eclipse use, inside eclipse android settings you fine the debug keystore location,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM