Java Google Maps v2 Projection.toScreenLocation(…)速度非常慢

Java Google Maps v2 Projection.toScreenLocation(…)速度非常慢,java,android,performance,google-maps,android-maps-v2,Java,Android,Performance,Google Maps,Android Maps V2,我已经在Android应用程序中将谷歌地图v1升级到v2 v2很好,等等,但有一种方法似乎是我一生中最慢的 Projection proj = map.getProjection(); Point point = proj.toScreenLocation(example.m_geopoint); toScreenLocation(…)非常慢,因此应用程序会减慢到无法使用的slowmotion。 该方法每帧可能更新100次,但在Google Maps v1上效果非常好 当我登录Android控

我已经在Android应用程序中将谷歌地图v1升级到v2

v2很好,等等,但有一种方法似乎是我一生中最慢的

Projection proj = map.getProjection();
Point point = proj.toScreenLocation(example.m_geopoint);
toScreenLocation(…)非常慢,因此应用程序会减慢到无法使用的slowmotion。 该方法每帧可能更新100次,但在Google Maps v1上效果非常好

当我登录Android控制台时,我看到:

10-06 13:53:04.460: D/dalvikvm(4889): GC_EXPLICIT freed 251K, 14% free 14622K/16839K, paused 3ms+5ms
10-06 13:53:05.859: D/dalvikvm(4889): GC_EXPLICIT freed 252K, 14% free 14622K/16839K, paused 2ms+5ms
10-06 13:53:07.222: D/dalvikvm(4889): GC_EXPLICIT freed 251K, 14% free 14622K/16839K, paused 3ms+6ms
...
在调用该方法时,此消息将一直出现

v2和v1之间的区别是:

pointOut = proj.toScreenLocation(geopointIn); // v2
projection.toPixels(geopointIn, pointOut); // v1

而v1似乎是更优化的解决方案。有什么方法可以让它更快吗?这是一个性能缺陷吗?

这个答案可能来得太晚了,但如果其他人遇到类似的问题,比如我,解决方案可能是在自己的服务器上使用Java的Graphics2D(其工作原理几乎与绘制画布相同)预渲染图像,然后在应用程序中下载。必须将地理点转换为笛卡尔坐标。 在应用程序中,您只需将图像定位为带有LatLngBounds的GroundOverlay:

并将其添加到地图中。。。


对我来说,这种方法工作得相当快。至少和Google Maps V1的速度一样快。

我来派对的时间非常晚,但我用android.graphics.Matrix找到了答案:

float getYMercator(double latitude){
    return (float)Math.log(Math.tan(Math.PI*(0.25+latitude/360.0)));
}
float [] fastToScreenLocation(GoogleMap map, List<LatLng> coordinates,int viewHeight, int viewWidth){
    VisibleRegion visibleRegion = map.getProjection().getVisibleRegion();
    Matrix transformMatrix = new Matrix();
    boolean ok = transformMatrix.setPolyToPoly(
            new float[] {
                    (float)visibleRegion.farLeft.longitude, getYMercator(visibleRegion.farLeft.latitude),
                    (float)visibleRegion.farRight.longitude, getYMercator(visibleRegion.farRight.latitude),
                    (float)visibleRegion.nearRight.longitude, getYMercator(visibleRegion.nearRight.latitude),
                    (float)visibleRegion.nearLeft.longitude, getYMercator(visibleRegion.nearLeft.latitude)
            },0,
            new float[] {
                    0, 0,
                    viewWidth, 0,
                    viewWidth,viewHeight,
                    0, viewHeight
            }, 0,
            4);
    if(!ok) return null;
    float[] points = new float[2*coordinates.size()];
    for(int i=0;i<coordinates.size();++i){
        LatLng location = coordinates.get(i);
        points[2*i]=(float)location.longitude;
        points[2*i+1]=getYMercator(location.latitude);
    }
    transformMatrix.mapPoints(points);
    return points;
}
float getYMercator(双纬度){
return(float)Math.log(Math.tan(Math.PI*(0.25+纬度/360.0));
}
float[]fastToScreenLocation(谷歌地图、列表坐标、int viewHeight、int viewWidth){
VisibleRegion VisibleRegion=map.getProjection().getVisibleRegion();
矩阵变换矩阵=新矩阵();
布尔ok=transformMatrix.SetPolytopoloy(
新浮动[]{
(float)visibleRegion.Farlefit.longitude,getYMercator(visibleRegion.Farlefit.latitude),
(float)visibleRegion.farRight.longitude,getYMercator(visibleRegion.farRight.latitude),
(float)visibleRegion.nearRight.longitude,getYMercator(visibleRegion.nearRight.latitude),
(浮动)visibleRegion.nearLeft.longitude,getYMercator(visibleRegion.nearLeft.latitude)
},0,
新浮动[]{
0, 0,
viewWidth,0,
viewWidth、viewHeight、,
0,视图高度
}, 0,
4);
如果(!ok)返回空值;
float[]点=新的float[2*坐标.size()];

对于(int i=0;这是很久以前的事了,但是我现在遇到了一些与这里描述的非常类似的性能问题。您在某个时候找到了解决方案吗?非常感谢!从我的测试来看,对于多个坐标确实要快得多,而对于单个坐标则要慢一点。您有相反的想法吗(从屏幕位置到lat lng)?另外,您知道如何测量地图的当前倾斜和旋转吗?