我是Android新手,正在使用Google地图活动处理Android应用。我已经用密钥库签署了应用程序,并生成了一个API密钥,这一切都运行良好。我已将API密钥作为字符串放在应用中,并添加了权限以及Android清单的关键字。我检查过是否在Google开发控制台中激活了API,并且它是。这一切都很好,我没有在Logcat中发现任何错误,也没有崩溃应用程序 - 但仍然没有看到在打开地图活动时屏幕上的任何位置。我使用Mac和三星Grand Prime进行开发和测试,并通过常规WiFI连接。Google地图显示空白屏幕的活动
Here's地图活动:
package de.die_web_agenten.www.batprice;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity {
//private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView myWebView = (WebView) findViewById(R.id.webview);
//myWebView.loadUrl("http://www.batprice.com");
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
//SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
// .findFragmentById(R.id.map);
//mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
//@Override
/*public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}*/
}
Here's Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.die_web_agenten.www.batprice">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="de.die_web_agenten.www.batprice.permission.MAPS_RECEIVE" />
<permission
android:name="de.die_web_agenten.www.batprice.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="@string/app_name" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
/>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<meta-data
android:name="com.google.android.gms:play-services-maps:8.4.0"
android:value="MyAPIkey" />
<activity
android:name=".ResultsActivity"
android:label="@string/title_activity_results"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".TrainingActivity"
android:label="@string/title_activity_training"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".SecondListActivity"
android:label="@string/title_activity_list"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".AndroidBarcodeQrExample"
android:label="@string/title_barcode_class"
android:theme="@style/AppTheme.NoActionBar" />
</application>
</manifest>
Here's布局文件webview.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView android:id="@+id/webview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
什么我在这里想念或做错了吗?任何提示和任何帮助将非常感谢,谢谢。
请检查您绑定到活动的布局。根据你的看起来你做错了什么。 – dhuma1981
@ dhuma1981 - 好的,非常感谢 - 我添加了活动使用的布局文件。这里有什么问题吗? –
为什么你使用WebView?只是谷歌关于如何整合谷歌地图到Android,你会得到你的答案 – dhuma1981