gpt4 book ai didi

java - Android 版 Google map 未呈现

转载 作者:行者123 更新时间:2023-12-01 10:00:55 25 4
gpt4 key购买 nike

我最近将所有工具更新到了 sdk 23。当我使用 Activity 向导创建 Google map Activity 时,它创建成功,但当我在设备上运行它时, map 不显示。我得到的只是左下角的谷歌 Logo 。

我尝试过的:

-使用 debug.keystore 中找到的 SHA-1 创建 API key

-重新生成的API key 和验证的包名称

-确保我启用了“Android 版 Google map v2”而不是“Google map v2”

-查看并尝试了该网站上我能找到的所有相关解决方案(+-10),但没有一个有效

-确保我将 google-play-services 作为项目依赖项

-确保 Google Play 服务与其他工具一起更新

我的 list :

<!--
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.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<permission android:name="com.venon.ranger.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.venon.ranger.permission.MAPS_RECEIVE"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

</activity>

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaxxxxxxxxxxxxxxxxxxxx" />

<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver android:name=".PushReceiver">
<intent-filter>

<!-- Do not modify this -->
<action android:name="pushy.me" />
</intent-filter>
</receiver>

<!-- Pushy Update Receiver -->
<!-- Do not modify - internal BroadcastReceiver that restarts the listener service -->
<receiver android:name="me.pushy.sdk.receivers.PushyUpdateReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />

<data android:scheme="package" />
</intent-filter>
</receiver>

<!-- Pushy Boot Receiver -->
<!-- Do not modify - internal BroadcastReceiver that restarts the listener service -->
<receiver android:name="me.pushy.sdk.receivers.PushyBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<!-- Pushy Socket Service -->
<!-- Do not modify - internal socket background service -->
<service android:name="me.pushy.sdk.services.PushySocketService" />
</application>

我的应用程序 Gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.venon.ranger"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'

}

我的MapActivity.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:apiKey = "AIzaxxxxxxxxxxxxxxxxxxxxxxxxxx"
tools:context="com.venon.ranger.MapsActivity" />

我的MapActivity.java

package com.venon.ranger;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

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 implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// 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 disturbance = new LatLng(-34, 151);

mMap.addMarker(new MarkerOptions().position(disturbance).title("Disturbance"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(disturbance));

}
}

我没有什么想法。

最佳答案

此问题通常与 Maps API Key 有关用于签署 list 。在 Google API 控制台 中创建 API key 时,您需要确保使用调试 keystore 。

当您准备好将应用程序启动到 Market 时,请设置 android:debuggable="false"在 AndroidManifest.xml 中并使用签名 API key

使用签名的 API key 时,仅当从 Android Market 安装应用程序时,MapView 才会显示。因此,MapView 将显示。

如果您的应用程序中有多个包,请注意,在创建 API key 时,您必须使用 android mainfest.xml 文件顶部包含的包名称

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
*package="com.xxx.xxx"*
android:versionCode="1"
android:versionName="1.0" >

这里有一个相关的堆栈溢出票证,其中讨论了 Google map 不渲染 map 的问题:Android and strange error with maps from google

关于java - Android 版 Google map 未呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36816804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com