我尝试了许多修复它的东西但是,我仍然看不到地图。我确定我的ApiKey
true
和Google Maps Android Api v2
处于有效状态。
如果我在模拟器上尝试它,它会崩溃。但是,如果我在真实的设备上尝试它,它可以工作,但我看不到地图,只有空白。
我的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; } }
清单
<?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>
答案 0 :(得分:0)
确保您安装了Google Play服务。您可以按照本教程http://wptrafficanalyzer.in/blog/google-maps-in-android-application-with-new-google-maps-android-api-v2-using-supportmapfragment/
进行操作答案 1 :(得分:0)
如果仅为调试目的生成API密钥,请确保您的设备执行应用程序的调试版本。
答案 2 :(得分:0)
你正在使用Support(不是FragmentActivity)与SupportMapFragment,我怀疑它会起作用。你使用的是哪个版本的android目标?在android 4之前你必须包含兼容性库。如果您在调试中,您必须从调试密钥库签名生成密钥,这是默认的eclipse使用,在eclipse android设置中,您可以使用调试密钥库位置,