2

我正在实施 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)

下面是产生问题的代码示例。

UpdateMap 方法在 Activity 的 onCreate 方法中只调用一次。UpdateMap 内部是 DrawUserLocationOnMap 调用。我愿意接受任何建议。

更新地图方法:

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));
    }
}

更新:

为了强制出错,我添加了每 200 毫秒调用一次 DrawUserLocationOnMap() 方法的循环。4-5秒后它崩溃了。

4

2 回答 2

5

我将首先解决您的代码的一些问题,并希望其中之一是使 Maps V2 库绊倒的原因。

  1. 不要animateCamera()在循环内多次调用。您的用户会头晕目眩。请在最后调用一次。

  2. 不要一直在相同的位置重新添加相同的标记,因为您的代码是通过调用它几十次(“每 200 毫秒。4-5 秒后它崩溃”)大概相同的模型数据,因为那要么是无效的生产代码(如果你真的这样做的话),要么是无效的测试(如果这纯粹是你强迫崩溃的产物)。

如果这些没有帮助,请慢慢开始注释掉部分代码,直到您可以精确地缩小触发无限递归的范围。我希望堆栈跟踪可能会具体显示代码中触发问题的位置,但这并没有解决。

于 2013-03-16T20:17:23.480 回答
0

澄清这里发生了什么。感谢@CommonsWare。

在 DrawUserLocationOnMap() 方法中,我有将 LatLng 对象添加到记录的 POptions 折线的 for 循环。问题是ProviderUtility.GPSTrackingProvider.GetGPSCoordinates(false)返回用户/设备访问的所有记录坐标。此方法返回新的(仅记录器)坐标和旧的、已绘制的坐标。我的错误在这里,我一遍又一遍地为相同的旧坐标添加 LatLng。这导致了 StackOverflow 错误。现在我已经修改了 DrawUserLocationOnMap() 的这一部分以仅添加新坐标。

于 2013-03-17T19:42:36.743 回答