地图未渲染。仅显示网格线
Posted
技术标签:
【中文标题】地图未渲染。仅显示网格线【英文标题】:Map not rendering. Only Grid lines are shown 【发布时间】:2018-03-26 22:16:16 【问题描述】:我正在使用百度地图(SDK 版本:4.5.2),但地图没有显示。相反,只显示网格线。
代码:
public class MainApp extends MultiDexApplication
@Override
public void onCreate()
super.onCreate();
SDKInitializer.initialize(this);
BaiduMapActivity
类:(此代码在 Kotlin 中。如果您需要此代码的 Java 等效项,请在下方留言。)
class BaiduMapActivity : BaseActivity()
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_baidu_map)
override fun onResume()
super.onResume()
bmapView.onResume()
build.gradle 文件:
buildscript
ext.kotlinVersion = '1.2.10'
repositories
maven url 'https://maven.fabric.io/public'
dependencies
//noinspection GradleDynamicVersion
classpath 'io.fabric.tools:gradle:1.+'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
//For green dao
apply plugin: 'org.greenrobot.greendao'
repositories
maven url 'https://maven.fabric.io/public'
maven url "https://jitpack.io"
jcenter()
android
configurations.all
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.0'
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig
applicationId "com.emerson.oversight"
minSdkVersion 16
targetSdkVersion 27
versionCode 6
versionName "1.6.2"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
dataBinding
enabled = true
lintOptions
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
disable 'MissingTranslation'
buildTypes
release
lintOptions
disable 'MissingTranslation'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
kapt generateStubs = true
dependencies
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar')
transitive = true
//AppCompat v7 support library
compile 'com.android.support:appcompat-v7:27.0.2'
//AppCompat v4 support library
compile 'com.android.support:support-v4:27.0.2'
//Support design
compile 'com.android.support:design:27.0.2'
//Google Maps
compile 'com.google.android.gms:play-services-maps:11.8.0'
//Retrofit - for making REST API calls
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
//For Runtime permissions
compile 'com.karumi:dexter:4.2.0'
//To set custom fonts
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
//Attaches bullets to viewpager
compile 'com.robohorse.pagerbullet:pagerbullet:1.0.8'
//Expandable recycler view
compile 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'
//For Graph
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
//Date time
compile 'com.wdullaer:materialdatetimepicker:3.2.1'
compile 'com.android.support:recyclerview-v7:27.0.2'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:27.0.2'
androidTestCompile 'com.android.support.test:runner:1.0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.support:gridlayout-v7:27.0.2'
compile 'com.android.support:cardview-v7:27.0.2'
compile 'jp.wasabeef:recyclerview-animators:2.2.6'
// compile 'com.ncornette.cache:okcache-control:1.1.1'
compile 'org.greenrobot:greendao:3.2.2'
compile 'net.danlew:android.joda:2.9.9'
compile 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.3'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'org.jetbrains.anko:anko-common:0.8.3'
compile 'me.dm7.barcodescanner:zbar:1.9.8'
compile 'io.reactivex:rxjava:1.2.0'
compile 'com.squareup:android-times-square:1.6.5@aar'
// notice that the compiler version must be the same than our gradle version
kapt 'com.android.databinding:compiler:3.2.0-alpha05'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2',
exclude group: 'com.android.support', module: 'support-annotations'
apply plugin: 'kotlin-android-extensions'
日志:
03-27 23:44:51.059 7163-7163/com.emerson.oversight D/ViewRootImpl@ebc9b08[BaiduMapActivity]: ThreadedRenderer.create() translucent=true
03-27 23:44:51.062 7163-7163/com.emerson.oversight D/InputTransport: Input channel constructed: fd=113
03-27 23:44:51.062 7163-7163/com.emerson.oversight D/ViewRootImpl@ebc9b08[BaiduMapActivity]: setView = DecorView@dbaa2a1[BaiduMapActivity] touchMode=true
03-27 23:44:51.074 7163-7163/com.emerson.oversight I/SemDesktopModeManager: registerListener: android.view.ViewRootImpl$3@1965e9e
03-27 23:44:51.076 7163-7163/com.emerson.oversight D/ViewRootImpl@a0e9d7f[BaiduMapActivity]: ThreadedRenderer.create() translucent=false
03-27 23:44:51.078 7163-7163/com.emerson.oversight D/InputTransport: Input channel constructed: fd=115
03-27 23:44:51.078 7163-7163/com.emerson.oversight D/ViewRootImpl@a0e9d7f[BaiduMapActivity]: setView = DecorView@6f71595[BaiduMapActivity] touchMode=true
03-27 23:44:51.079 7163-7163/com.emerson.oversight D/ViewRootImpl@52ebfdf[Toast]: MSG_RESIZED_REPORT: frame=Rect(318, 2414 - 1122, 2568) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
03-27 23:44:51.102 7163-7163/com.emerson.oversight D/ViewRootImpl@ebc9b08[BaiduMapActivity]: dispatchAttachedToWindow
03-27 23:44:51.127 7163-7163/com.emerson.oversight D/ViewRootImpl@ebc9b08[BaiduMapActivity]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[37,1235][1403,1641] result=0x27 surface=isValid=true 547931812352 surfaceGenerationChanged=true
mHardwareRenderer.initialize() mSurface=isValid=true 547931812352 hwInitialized=true
03-27 23:44:51.135 7163-7163/com.emerson.oversight D/ViewRootImpl@a0e9d7f[BaiduMapActivity]: dispatchAttachedToWindow
03-27 23:44:51.160 7163-7163/com.emerson.oversight D/ViewRootImpl@a0e9d7f[BaiduMapActivity]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][1440,2960] result=0x27 surface=isValid=true 547759640576 surfaceGenerationChanged=true
mHardwareRenderer.initialize() mSurface=isValid=true 547759640576 hwInitialized=true
03-27 23:44:51.174 7163-7163/com.emerson.oversight D/SurfaceView: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,393][1440,2792] result=0x7 surface=Surface(name=null)/@0x479929b isValid=true 547759644160
03-27 23:44:51.221 7163-7163/com.emerson.oversight D/ViewRootImpl@ebc9b08[BaiduMapActivity]: MSG_WINDOW_FOCUS_CHANGED 1
mHardwareRenderer.initializeIfNeeded()#2 mSurface=isValid=true 547931812352
03-27 23:44:51.233 7163-7163/com.emerson.oversight D/ViewRootImpl@a0e9d7f[BaiduMapActivity]: Relayout returned: oldFrame=[0,0][1440,2960] newFrame=[0,0][1440,2960] result=0x1 surface=isValid=true 547759640576 surfaceGenerationChanged=false
03-27 23:44:51.237 7163-7163/com.emerson.oversight D/SurfaceView: Relayout returned: oldFrame=[0,393][1440,2792] newFrame=[0,393][1440,2792] result=0x1 surface=Surface(name=null)/@0x479929b isValid=true 547759647744
03-27 23:44:51.259 7163-7163/com.emerson.oversight D/ViewRootImpl@ebc9b08[BaiduMapActivity]: MSG_RESIZED_REPORT: frame=Rect(37, 1235 - 1403, 1641) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
03-27 23:44:51.262 7163-7163/com.emerson.oversight D/TextView: setTypeface with style : 0
03-27 23:44:51.263 7163-7163/com.emerson.oversight D/TextView: setTypeface with style : 0
03-27 23:44:51.264 7163-7163/com.emerson.oversight D/ViewRootImpl@a0e9d7f[BaiduMapActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 1440, 2960) ci=Rect(0, 84 - 0, 168) vi=Rect(0, 84 - 0, 168) or=1
03-27 23:44:51.339 7163-7163/com.emerson.oversight D/ViewRootImpl@ce7e452[SelectTripActivity]: mHardwareRenderer.destroy()#1
03-27 23:44:51.359 7163-7163/com.emerson.oversight D/ViewRootImpl@ce7e452[SelectTripActivity]: Relayout returned: oldFrame=[0,0][1440,2960] newFrame=[0,0][1440,2960] result=0x5 surface=isValid=false 0 surfaceGenerationChanged=true
03-27 23:44:54.241 7163-7163/com.emerson.oversight D/ViewRootImpl@52ebfdf[Toast]: mHardwareRenderer.destroy()#4
03-27 23:44:54.247 7163-7163/com.emerson.oversight D/ViewRootImpl@52ebfdf[Toast]: dispatchDetachedFromWindow
03-27 23:44:54.273 7163-7163/com.emerson.oversight D/InputTransport: Input channel destroyed: fd=108
03-27 23:44:54.275 7163-7163/com.emerson.oversight I/SemDesktopModeManager: unregisterListener: android.view.ViewRootImpl$3@c320e7e
03-27 23:44:59.878 7163-7168/com.emerson.oversight I/art: Do partial code cache collection, code=124KB, data=114KB
03-27 23:44:59.880 7163-7168/com.emerson.oversight I/art: After code cache collection, code=123KB, data=113KB
Increasing code cache capacity to 512KB
03-27 23:45:00.819 7163-7163/com.emerson.oversight D/ViewRootImpl@ce7e452[SelectTripActivity]: Relayout returned: oldFrame=[0,0][1440,2960] newFrame=[0,0][1440,2960] result=0x5 surface=isValid=false 0 surfaceGenerationChanged=false
03-27 23:45:00.874 7163-7163/com.emerson.oversight I/CacheManager: TraxxEntity is null
03-27 23:45:01.533 7163-7163/com.emerson.oversight D/ViewRootImpl@ebc9b08[BaiduMapActivity]: mHardwareRenderer.destroy()#4
03-27 23:45:01.534 7163-7163/com.emerson.oversight D/ViewRootImpl@ebc9b08[BaiduMapActivity]: dispatchDetachedFromWindow
03-27 23:45:01.572 7163-7163/com.emerson.oversight D/InputTransport: Input channel destroyed: fd=113
03-27 23:45:01.575 7163-7163/com.emerson.oversight I/SemDesktopModeManager: unregisterListener: android.view.ViewRootImpl$3@7f928ab
03-27 23:45:01.618 7163-7163/com.emerson.oversight D/ViewRootImpl@a0e9d7f[BaiduMapActivity]: MSG_WINDOW_FOCUS_CHANGED 1
mHardwareRenderer.initializeIfNeeded()#2 mSurface=isValid=true 547759640576
03-27 23:45:01.619 7163-7163/com.emerson.oversight V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@15fb381 nm : com.emerson.oversight ic=null
03-27 23:45:01.619 7163-7163/com.emerson.oversight I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
03-27 23:45:01.631 7163-7163/com.emerson.oversight D/InputTransport: Input channel constructed: fd=104
Input channel destroyed: fd=103
03-27 23:45:01.631 7163-7163/com.emerson.oversight E/ViewRootImpl: sendUserActionEvent() returned.
库的结构:
结果如下。应用程序运行良好,但仅显示网格线且地图不可见。
可能的原因是什么?
【问题讨论】:
您能否检查日志并将您可能在那里找到的相关错误添加到您的问题中 @petey 我已经添加了日志。 【参考方案1】:几个选项可能是原因:
Manifest 中没有添加 Api Key API Key 绑定到错误的 SHA1,或者错误的包名 使用模拟器。根据我的测试,从来没有在模拟器上运行过,但在真实设备上运行良好(我打赌这个,因为我在你的日志中没有看到与百度的通信错误)。【讨论】:
【参考方案2】:尝试使用china ***,然后查看地图是否加载
【讨论】:
以上是关于地图未渲染。仅显示网格线的主要内容,如果未能解决你的问题,请参考以下文章
如何在 openlayers 的地图上显示全球 UTM 网格?
使用 Collider Unity 将线渲染转换为 3d 网格