0

我尝试了很多东西来修复它,但我仍然看不到地图。我确定我ApiKey的是true并且Google Maps Android Api v2是活跃的。

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

我的日志猫

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;     } } 

显现

<?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>
4

3 回答 3

0

确保您安装了 google play 服务。您可以按照本教程http://wptrafficanalyzer.in/blog/google-maps-in-android-application-with-new-google-maps-android-api-v2-using-supportmapfragment/

于 2013-10-04T22:46:24.320 回答
0

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

于 2013-10-04T22:50:42.910 回答
0

您正在使用带有 SupportMapFragment 的 Activity(不是 FragmentActivity),我怀疑这会起作用。您使用的是哪个版本的 android 目标?在 android 4 之前,您也必须包含兼容性库。如果您处于调试状态,则必须从默认 eclipse 使用的调试密钥库签名生成密钥,在 eclipse android 设置中,您可以微调调试密钥库位置,

于 2013-10-04T22:56:43.610 回答