屏幕上有5-10个标记,Android的谷歌地图非常慢。大约100,它几乎无法使用。我搜索的范围很广,但我似乎无法找到其他人解决这个问题。讨论javascript API的人似乎认为数以千计的标记是合理的,所以我认为我必须在android上做错了。
要明确的是,添加标记很好,但是一旦它们在屏幕上,平移就会非常慢。我打开了#34; Profile GPU Rendering"设置和具有标记的帧需要更长的时间来渲染。
我正在使用play-services-maps 11.6.0
这是代码。我只是在活动中添加一次标记。
fun addMarkers(latLngs: List<LatLng>){
for (latLng in latLngs){
mMap.addMarker(MarkerOptions()
.position(latLng)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_location_marker_red)))
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.testapp.TrackVehicleActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/track_vehicle_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/trackVehiclesMap"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
知道这里会发生什么,或进一步的调试技巧?我唯一能想到的就是我的布局在某种程度上搞砸了。谢谢!
编辑:我在Moto G4 plus上测试了这个,所以我不认为这只是电话慢的问题