我正在尝试在披萨应用中实现谷歌我的应用程序,但它显示空白页面该怎么办?
在我的java代码下面。
public class FindUsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_us);
// 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;
LatLng sydney = new LatLng(56.855776, 14.829839);
Marker DSlocation = mMap.addMarker(new MarkerOptions().position(sydney).title("Maestro restaurang &
pizzeria").snippet("Click Navigation icon below for navigation"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,18));
} }
我的xml文件
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.yodgor777.maestro.FindUsActivity" />
我的清单
<?xml version="1.0" encoding="utf-8"?> <manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yodgor777.maestro">
不需要使用ACCESS_COARSE / FINE_LOCATION权限 Google Maps Android API v2,但您必须指定粗略或精细 “MyLocation”功能的位置权限。 - &GT;
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
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=".HomeScreenActivity"
android:label="@string/title_activity_home_screen" />
<activity android:name=".MainActivity" />
<activity android:name=".Information" />
<!--
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" />
<activity
android:name=".FindUsActivity"
android:label="@string/title_activity_find_us"></activity>
</application>
</manifest>
答案 0 :(得分:1)
在manifest.xml中添加此权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
更改您的谷歌地图Apikey,然后尝试一下,并在google map api
键enable
之后检查。
答案 1 :(得分:0)
启用Maps API
接下来,添加包名称和指纹。这提供了两个字段,一个用于添加包名称,另一个用于从应用程序签名密钥添加SHA1。
您可以使用以下命令生成SHA1:
keytool -list -v -keystore debug.keystore
创建SHA1密钥并将其输入文本字段后,单击蓝色的“创建”按钮。然后,系统会向您显示一个对话框,其中包含您需要添加到Android应用中以访问Maps API的API密钥。