我是Android的新用户,正在开发一款带有Google地图活动的Android应用。我已经使用密钥库签署了应用程序并生成了一个API密钥,这一切都运行良好。我已将API密钥作为字符串放在应用程序中,并将权限和密钥添加到Android清单中。我已经检查过是否在Google开发者控制台中激活了API,而且确实如此。这一切看起来很好,我没有在Logcat中出现任何错误,也没有崩溃应用程序 - 但是,在打开地图活动时,我仍然看不到屏幕上的任何位置。我正在使用Mac和Samsung Grand Prime进行开发和测试,我通过常规WiFI连接。
这是地图活动:
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));
}*/
}
这是Android Manifest:
<?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>
这是布局文件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>
我在这里错过了什么或做错了什么?任何提示和任何帮助将非常感谢,谢谢。
答案 0 :(得分:1)
您的代码不会制作Google地图,它只是一个WebView。