建立在谷歌地图标记时IllegalStateException异常(IllegalStateExce

2019-10-21 17:31发布

你好我想显示在谷歌地图V2一些标记点。 一切都很好,直到我发现了这个错误。 因为如果我加载地图,上面有两个指针,然后关闭并重新载入它的一些原因,我再次得到这个消息:

“没有IllegalStateException异常包括点”

当我打电话了,会出现此错误:

 LatLngBounds bounds = builder.build();

这是我如何把地图上的点:

    // Point the map's listeners at the listeners implemented by the cluster
    // manager.

    googleMap.setOnMarkerClickListener(mClusterManager);

    builder = new LatLngBounds.Builder();

    for (Ad ad : Constants._results)
    {
        builder.include(new LatLng(ad.getLat(), ad.getLon()));
    }

    googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
        @Override
        public void onCameraChange(CameraPosition cameraPosition)
        {
            int padding = 50; // offset from edges of the map in pixels
            try{
                LatLngBounds bounds = builder.build();
                CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
                googleMap.moveCamera(cu);
                googleMap.setOnCameraChangeListener(mClusterManager);
            }catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    });

谁能帮帮忙?

logcat的:

-30 14:11:11.267  20651-20874/com.myapp.user E/com.newrelic.agent.android﹕ Error in fireOnHarvestFinalize
java.util.ConcurrentModificationException
        at java.util.HashMap$HashIterator.nextEntry(HashMap.java:806)
        at java.util.HashMap$EntryIterator.next(HashMap.java:843)
        at java.util.HashMap$EntryIterator.next(HashMap.java:841)
        at com.newrelic.agent.android.metric.MetricStore.getAllByScope(MetricStore.java:63)
        at com.newrelic.agent.android.metric.MetricStore.getAllUnscoped(MetricStore.java:74)
        at com.newrelic.agent.android.harvest.HarvestDataValidator.ensureActivityNameMetricsExist(HarvestDataValidator.java:41)
        at com.newrelic.agent.android.harvest.HarvestDataValidator.onHarvestFinalize(HarvestDataValidator.java:15)
        at com.newrelic.agent.android.harvest.Harvester.fireOnHarvestFinalize(Harvester.java:580)
        at com.newrelic.agent.android.harvest.Harvester.execute(Harvester.java:271)
        at com.newrelic.agent.android.harvest.HarvestTimer.tick(HarvestTimer.java:73)
        at com.newrelic.agent.android.harvest.HarvestTimer.tickIfReady(HarvestTimer.java:56)
        at com.newrelic.agent.android.harvest.HarvestTimer.run(HarvestTimer.java:32)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:279)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:152)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:841)

Answer 1:

我觉得你的问题就在这里

 for (Ad ad : Constants._results)
    {
        builder.include(new LatLng(ad.getLat(), ad.getLon()));
    }

Constants._results必须是空的,所以在你的建设者没有经纬度点。 调试和检查。



Answer 2:

在API中,我们发现:

公众的LatLngBounds(西南的LatLng,东北的LatLng):IllegalArgumentException如果东北角的纬度是西南角的纬度下方。

在代码中,异常被启动时计算范围列表为空:

LatLngBounds.Builder builder = LatLngBounds.builder();
for(ModelLatLngDisplay p: yourList)
{
    builder = builder.include(p.latLng);
}
return builder.build();


Answer 3:

在UI线程上运行标记的任务。

runOnUiThread(new Runnable() {
    @Override
    public void run() {
        //Add your marker here...
    }
});


文章来源: IllegalStateException when creating markers on google map