问题
i just want to ask i want to make googlemaps apps on android.. i have follow instruction from many website (include from google developer) but the apps doesn't work on my real device (on Android 4.2.2) can anyone help me? Please.. The Code Look Like This.
xml file :
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
The AndroidManifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wilis.googlemaps"
android:versionCode="1"
android:versionName="1.0" >
<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"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<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.wilis.googlemaps.GoogleMaps"
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="AIzaSyAOGow0GmvoOi87cCFQffmRVz4SNmEWnP0"/>
</application>
</manifest>
And The Main Activity file :
package com.wilis.googlemaps;
import android.os.Bundle;
import android.app.Activity;
public class GoogleMaps extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
回答1:
Check this :
Google Maps V2 , Google Maps V2 and Example
Hope this helps.
回答2:
Only gray backgrounds shows in case of incorrect API_KEY. Probably you mixed up debug and production keys.
回答3:
Use MapView in your xml
<com.google.android.gms.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="AIzaSyCpC852JtX3dHjqGP6UnJBygJUdO0w_pBY"
android:clickable="true"
android:id="@+id/mMapView"
android:enabled="true" />
and Use the below code for the GoogleActivity:
public class GoogleActivity extends Activity {
private GoogleMap mGglMpInstance;
private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
MapsInitializer.initialize(MainActivity.this);
} catch (GooglePlayServicesNotAvailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
initailizeLayout(savedInstanceState);
}
private void initailizeLayout(Bundle savedInstanceState){
mMapView=(MapView)findViewById(R.id.mMapView);
mMapView.onCreate(savedInstanceState);
mGglMpInstance=mMapView.getMap();
}
回答4:
See here,just change the api key with your key in manifest file and follow these steps: and make sure that generate api key with package name which is mentioned in android manifest file and your google_play_services_lib project should be present in your project's work space only.
Manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<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" />
<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" >
<activity
android:name="com.geeklabs.map.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="replace with your API key"/>
</application>
</manifest>
MainActivity.java:
package com.geeklabs.map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
After got this let me know.
And make sure following steps done correct or not:
Steps: * to ensure that device has Google Play services APK * to install Google Play Service rev. more than 2
- to create project at https://code.google.com/apis/console/
- to enable "Google Maps Android API v2"
- to register of SHA1 in project (NOW, YOU NEED WRITE SHA1;your.app.package.name) at APIs console and get API KEY
- to copy directory ANDROID_SDK_DIR/extras/google/google_play_services/libproject/google-play-services_lib to root of your project
- to add next line to the YOUR_PROJECT/project.properties
android.library.reference.1=google-play-services_lib
- to add next lines to the YOUR_PROJECT/proguard-project.txt
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
Okay, now you ready to create your own Google Map app with using Google Map APIs V2 for Android.
If you create application with min SDK = 8, please use android support library v4 + SupportMapFragment instead of MapFragment.
回答5:
try to enable Googlre map api v2 in services of google api console
you have copy pasted the api key try to create a api key your own ...
how to create a Google API key
来源:https://stackoverflow.com/questions/20341707/the-map-doesnt-show-only-show-grid-and-show-grey-background