gpt4 book ai didi

android - 在 getMapAsync() 中调用 GoogleMap.getProjection() 时 IllegalArgumentException left == right

转载 作者:太空宇宙 更新时间:2023-11-03 11:02:35 24 4
gpt4 key购买 nike

更新到最新的支持库(版本 24.2.0)并将 compileSdkVersion 设置为 24 后,我开始在旋转后调用 GoogleMap.getProjection() 时看到 IllegalArgumentException left == right。

map 的初始渲染有效,当旋转回原始方向时,不会抛出异常。它只是从原来的方向到另一个方向(每次旋转从原来的方向改变到新的方向时都会发生异常)

使用相同代码返回支持库的 23.4.0 版不会出现此行为。所以,我不确定最新的支持库是否存在问题(这应该与 GoogleMap 无关),或者最新版本只是在我的代码中暴露了一个错误。

两个版本都使用相同的 Google Play 服务 (9.4.0)。

我读过关于应该在 onMapLoadedCallback 内部访问投影的建议,但我的假设是在 getMapAsync 方法内调用 GoogleMap 实例上的方法会很好,因为这应该可以保证 map 可以使用。

堆栈跟踪:

java.lang.IllegalArgumentException: left == right
at android.opengl.Matrix.frustumM(Matrix.java:327)
at com.google.maps.api.android.lib6.gmm6.n.b.b.j(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.b.b.l(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.b.b.b(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.b.b.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.b.b.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.v.a(Unknown Source)
at com.google.maps.api.android.lib6.d.aw.a(Unknown Source)
at com.google.android.gms.maps.internal.cb.onTransact(SourceFile:82)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.internal.IProjectionDelegate$zza$zza.getVisibleRegion(Unknown Source)
at com.google.android.gms.maps.Projection.getVisibleRegion(Unknown Source)
at com.google.maps.android.clustering.view.DefaultClusterRenderer$RenderTask.run(DefaultClusterRenderer.java:363)
at java.lang.Thread.run(Thread.java:818)

相关 fragment 如下:

 public class MyMapFragment extends Fragment
{
@Nullable
private SupportMapFragment m_mapFragment;

// fragment setup code removed for this snippet

/** Assign the map fragment variable on resume. This is necessary for orientation change events */
@Override
public void onResume ()
{
super.onResume();

// We can get here in (at least) 3 different ways:
// 1. The first time this fragment is created.
// In this case, we will not have a local reference to a map fragment and will will add
// it if we are the currently displaying fragment.
// 2. After rotation
// Because the actual map fragment is maintained by our activity, the map fragment will
// have been recreated and our reference to it will no longer be valid.
// 3. After a pause event (such as the device going into power saving mode).
// We should still have a reference to the current map fragment and it should be
// valid. We can test that by checking if the map fragment is attached. This is done
// in the setMapFragment() method.
//
final AlbumActivity activity = (AlbumActivity)getActivity();

Fragment currentFragment = activity.getCurrentItemFragment() ;

if( m_mapFragment == null && this == currentFragment )
{
setMapFragment( activity.getMapFragment() );
}
else if ( m_mapFragment != null )
{
setMapFragment( activity.getMapFragment() );
}
else
{
// just update the map
updateMap() ;
}
}

private void updateMap()
{
if ( m_mapFragment == null )
{
return;
}

m_mapFragment.getMapAsync( new OnMapReadyCallback()
{
@Override
public void onMapReady( GoogleMap googleMap )
{
try
{
googleMap.clear();

// Exception thrown here!
final Projection projection = googleMap.getProjection() ;
final VisibleRegion visibleRegion = projection.getVisibleRegion() ;

LatLngBounds mapBounds = visibleRegion.latLngBounds;

// more done on map here (markers, etc.)
}
catch ( IllegalStateException e )
{
// basically, wait 100 ms and try again. However,
// the exception seems to not go away until rotation goes back to original orientation
configureAfterDelay();
}
}
} ) ;
}

public void setMapFragment ( @Nullable SupportMapFragment mapFragment )
{
// The working assumption is that our map fragment, if already added, is added to
// our current fragment.
if ( mapFragment != null && mapFragment.isAdded() == false )
{
final FragmentManager fragmentManager = getChildFragmentManager();

// Add the map view to the current view
fragmentManager.beginTransaction()
.add( R.id.mapview_container, mapFragment, MAP_FRAGMENT_TAG )
.commit();

fragmentManager.executePendingTransactions();
}

m_mapFragment = mapFragment;

updateMap( );
}

我在其他地方看到了以下问题,但没有找到解决方案:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=8724

最佳答案

我知道已经很晚了,但我今天刚遇到这个问题...问题是本地图的大小为 0 并且您尝试访问 map.Projection.VisibleRegion 时。错误消息的字面意思是投影的左侧与投影的右侧相同,如果 map View 的宽度为 0,就会发生这种情况。要绕过它,请确保您只访问 map 投影的 VisibleRegion当 mapView 的宽度 > 0 时。

var extent = mapView.Width > 0 ? map.Projection.VisibleRegion.LatLngBounds : null;

关于android - 在 getMapAsync() 中调用 GoogleMap.getProjection() 时 IllegalArgumentException left == right,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39212036/

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