我正在实施Google Maps V2,我正在使用从外部GPX文件,设备路径,设备当前位置和交付点位置接收的传送路径。事情是它大部分时间都有效...... 我得到的错误(当它不工作时)是下一个:
03-16 20:48:37.811: I/dalvikvm(16510): threadid=30: stack overflow on call to Lmaps/t/bx;.d:FLLL
03-16 20:48:37.811: I/dalvikvm(16510): method requires 40+20+0=60 bytes, fp is 0x60223318 (24 left)
03-16 20:48:37.811: I/dalvikvm(16510): expanding stack end (0x60223300 to 0x60223000)
03-16 20:48:37.811: I/dalvikvm(16510): Shrank stack (to 0x60223300, curFrame is 0x60226e54)
03-16 20:48:37.821: D/gralloc(16510): unmap_buffer: Successfully unmapped 0xa5000 bytes at address 0x60416000, SharedFd=89, map_count = 3
03-16 20:48:37.821: D/gralloc(16510): unmap_buffer: Successfully unmapped 0xa5000 bytes at address 0x604bb000, SharedFd=96, map_count = 2
03-16 20:48:37.881: W/dalvikvm(16510): threadid=30: thread exiting with uncaught exception (group=0x409f61f8)
03-16 20:32:23.471: E/AndroidRuntime(16283): FATAL EXCEPTION: GLThread 1827
03-16 20:32:23.471: E/AndroidRuntime(16283): java.lang.StackOverflowError
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.bx.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.bx.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
03-16 20:32:23.471: E/AndroidRuntime(16283): at maps.t.cg.a(Unknown Source)
以下是生成问题的代码示例。
在Activity的onCreate方法中只调用一次UpdateMap方法。 UpdateMap内部是DrawUserLocationOnMap调用。我愿意接受任何建议。
UpdateMap方法:
private void UpdateMap() {
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
int i = 0;
// GPS COORDINATES RECEIVED FROM GPX FILE
PolylineOptions pOptions = new PolylineOptions();
LatLng initialCameraPosition = null;
for (GpxTrackModel trackModel : ProviderUtility.GpxProvider.GpxTracks) {
for (GpxTrackCoordinateModel coorModel : trackModel.getTrackCoordinates()) {
if (i == 0)
initialCameraPosition = new LatLng(coorModel.getLatitude(), coorModel.getLongitude());
pOptions.add(new LatLng(coorModel.getLatitude(), coorModel.getLongitude()));
i++;
}
// ADDING DESTINATION MARKERS (LAST LOCATION IN TRACK SEGMENT)
MarkerOptions mOptions = new MarkerOptions();
mOptions.draggable(false);
GpxTrackCoordinateModel model = trackModel.getTrackCoordinates().get(trackModel.getTrackCoordinates().size() - 1);
mOptions.position(new LatLng(model.getLatitude(), model.getLongitude()));
mOptions.title(trackModel.getName());
map.addMarker(mOptions).showInfoWindow();
map.animateCamera(CameraUpdateFactory.newLatLngZoom(initialCameraPosition, 14));
DrawUserLocationOnMap();
}
pOptions.color(Color.parseColor("#FF0000"));
map.addPolyline(pOptions);
}
DrawUserLocationOnMap方法:
PolylineOptions recordedPOptions = null;
MarkerOptions userLocation = null;
private void DrawUserLocationOnMap() {
// RECORDED GPS DATA WITH GREEN LINE
if (recordedPOptions == null)
recordedPOptions = new PolylineOptions();
// ADDING SAVED USER GPS COORDINATES FROM DATABASE AND DRAWING PATH
ArrayList<GPSTrackingModel> list = ProviderUtility.GPSTrackingProvider.GetGPSCoordinates(false);
for (GPSTrackingModel recordedGps : list)
recordedPOptions.add(new LatLng(Double.parseDouble(recordedGps.getLatitude()), Double.parseDouble(recordedGps.getLongitude())));
recordedPOptions.color(Color.parseColor("#00FF00"));
map.addPolyline(recordedPOptions);
// ADDING CURRENT LOCATION MARKER
GPSTrackingModel lastPosition = ProviderUtility.GPSTrackingProvider.GetLastCoordinate();
if (lastPosition != null && lastPosition.getLatitude() != null
&& !lastPosition.getLatitude().equals("")
&& lastPosition.getLongitude() != null
&& !lastPosition.getLongitude().equals("")) {
LatLng lp = new LatLng(Double.parseDouble(lastPosition.getLatitude()), Double.parseDouble(lastPosition.getLongitude()));
if (userLocation == null) {
userLocation = new MarkerOptions();
userLocation.draggable(false);
userLocation.position(lp);
userLocation.title("My current location");
userLocation.icon(BitmapDescriptorFactory.fromResource(R.drawable.currentlocation));
map.addMarker(userLocation);
} else
userLocation.position(lp);
float zoom = map.getCameraPosition().zoom;
if (zoom < 14)
zoom = 14;
map.animateCamera(CameraUpdateFactory.newLatLngZoom(lp, zoom));
}
}
更新
为了强制错误,我添加了每200ms调用DrawUserLocationOnMap()方法的循环。 4-5秒后坠毁了。
答案 0 :(得分:4)
我首先要解决您的代码中的一些问题,并希望其中一个是绊倒Maps V2库。
不要在循环内多次调用animateCamera()
。您的用户会感到头晕目眩。请在结束时拨打一次。
不要在相同的位置继续重新添加相同的标记,因为你的代码是通过你调用它几十次(“每200ms。在4-5秒之后崩溃”)来完成的可能是相同的模型数据,因为它们是无效的生产代码(如果你真的这样做)或无效的测试(如果这纯粹是你如何强迫崩溃的工件)。
如果这些没有帮助,请慢慢开始注释掉部分代码,直到您可以精确缩小触发无限递归的内容。我希望堆栈跟踪可能会在代码中明确显示问题被触发的位置,但这并没有成功。
答案 1 :(得分:0)
澄清这里发生的事情。 感谢@CommonsWare。
在DrawUserLocationOnMap()方法中,我有for循环,将LatLng对象添加到recordedPOptions折线。问题是 ProviderUtility.GPSTrackingProvider.GetGPSCoordinates(false)返回用户/设备访问过的所有记录坐标。此方法返回新的(仅记录器)坐标和旧的已绘制坐标。我的错误就在这里,我一遍又一遍地为同样的旧坐标添加LatLng。这导致StackOverflow错误。现在我修改了DrawUserLocationOnMap()的这一部分,只添加新的坐标。