当我尝试将MapRoute对象添加到地图时,我似乎在某些旧设备上出现内存不足错误。通常发生在大约城市规模以外的路线上,特别是在美国各地的非常长的路线上。我尝试过仿真器设备(Nexus 4.4.4)和物理设备(Samsung Galaxy Prevail 4.4.4)。这是我计算路线的代码:
PlaceServices placeServices = new PlaceServices(getActivity());
placeServices.calculateRoute(pickupMarker.getCoordinate(), dropoffMarker.getCoordinate(),
new PlaceServices.RouteListener() {
@Override
public void gotRoute(MapRoute mapRoute) {
if(mapRoute != null) {
map.addMapObject(mapRoute);
GeoBoundingBox gbb = mapRoute.getRoute().getBoundingBox();
// Here is where I get an OOM
map.zoomTo(gbb, Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
}
}
});
这是我片段中回调的结果:
Error in converting images
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:620)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:634)
at com.here.android.mpa.internal.x.a(DiskCache.java:447)
at com.here.android.mpa.internal.x$b.a(DiskCache.java:399)
at com.here.android.mpa.internal.x$b.doInBackground(DiskCache.java:381)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
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)
有人遇到过这个问题吗?它没有影响更新的设备,我已经在Nexus 6上测试过没有问题。
堆栈跟踪:
const http = require('http');
const express = require('express');
const socketIO = require('socket.io');
var app = express();
var server = http.createServer(app);
var io = socketIO(server);
app.use(express.static(__dirname + '/public'));
const port = process.env.PORT || 3000;
// add your socketio code here
server.listen(port, () => {
console.log(`Server is up on port ${port}!`);
});
更新:由于问题是零星的,我花了一分钟来缩小范围,但错误发生在zoomTo,而不是向地图添加对象。我已经更新了标题和评论。
答案 0 :(得分:0)
在我计算修复问题的路线之前,我最终调用了zoomTo()方法,猜测尝试添加路径对象并同时缩放是不好的:
// Zoom to markers before the route is calculated to avoid OOM on some devices.
if(pickupCoordinate != null && dropoffCoordinate != null) {
GeoBoundingBox geoBoundingBox;
geoBoundingBox = Util.calculateBoundingBox(pickupCoordinate, dropoffCoordinate);
map.zoomTo(geoBoundingBox, Map.Animation.LINEAR, Map.MOVE_PRESERVE_ORIENTATION);
}
PlaceServices placeServices = new PlaceServices(getActivity());
placeServices.calculateRoute(pickupMarker.getCoordinate(), dropoffMarker.getCoordinate(),
new PlaceServices.RouteListener() {
@Override
public void gotRoute(MapRoute mapRoute) {
if(mapRoute != null) {
map.addMapObject(mapRoute);
}
}
});