在 google 地图上创建标记时出现 IllegalStateException
IllegalStateException when creating markers on google map
您好,我正在尝试在 Google 地图 v2 上显示一些标记点。一切都很好,直到我发现这个错误。出于某种原因,如果我加载带有 2 个指针的地图,然后关闭它并再次重新加载它,我会收到此消息:
"IllegalStateException no included points"
当我调用时出现此错误:
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.access1(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)
运行 UI 线程上的标记任务。
runOnUiThread(new Runnable() {
@Override
public void run() {
//Add your marker here...
}
});
在API中,我们发现:
public LatLngBounds (LatLng southwest, LatLng northeast): IllegalArgumentException if the latitude of the northeast corner is below the latitude of the southwest corner.
在您的代码中,当计算边界的列表为空时启动异常:
LatLngBounds.Builder builder = LatLngBounds.builder();
for(ModelLatLngDisplay p: yourList)
{
builder = builder.include(p.latLng);
}
return builder.build();
我认为你的问题出在这里
for (Ad ad : Constants._results)
{
builder.include(new LatLng(ad.getLat(), ad.getLon()));
}
Constants._results 必须为空,因此您的构建器中没有 LatLng 点。调试检查。
您好,我正在尝试在 Google 地图 v2 上显示一些标记点。一切都很好,直到我发现这个错误。出于某种原因,如果我加载带有 2 个指针的地图,然后关闭它并再次重新加载它,我会收到此消息:
"IllegalStateException no included points"
当我调用时出现此错误:
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.access1(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)
运行 UI 线程上的标记任务。
runOnUiThread(new Runnable() {
@Override
public void run() {
//Add your marker here...
}
});
在API中,我们发现:
public LatLngBounds (LatLng southwest, LatLng northeast): IllegalArgumentException if the latitude of the northeast corner is below the latitude of the southwest corner.
在您的代码中,当计算边界的列表为空时启动异常:
LatLngBounds.Builder builder = LatLngBounds.builder();
for(ModelLatLngDisplay p: yourList)
{
builder = builder.include(p.latLng);
}
return builder.build();
我认为你的问题出在这里
for (Ad ad : Constants._results)
{
builder.include(new LatLng(ad.getLat(), ad.getLon()));
}
Constants._results 必须为空,因此您的构建器中没有 LatLng 点。调试检查。