0

我正在尝试创建一个应用程序来在 Google 地图上绘制我们的山地自行车道。我已经让谷歌地图部分工作了。但是,一旦我尝试绘制几个地理点并将它们连接起来,它会显示地理点并连接它们,但谷歌地图会停止显示。仅显示灰色瓷砖。这是我绘制有效点之前的代码。

public class DPHTmaps extends MapActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        MapController mMapController;
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mMapController = mapView.getController();
        mMapController.setZoom(18);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}

然后我把我的代码改成这个来绘制和连接几个地理点,它把地图图块变成灰色。

public class DPHTmaps extends MapActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        MapController mMapController;
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mMapController = mapView.getController();
        mMapController.setZoom(18);
        // Two points in Backside trail
        GeoPoint point1 = new GeoPoint(-91777756,43311836);
        GeoPoint point2 = new GeoPoint(-91777627,43311718);
        mMapController.setCenter(point2);
        // Pass the geopoints to the overlay class
        MapOverlay mapOvlay = new MapOverlay(point1, point2);
        mapView.getOverlays().add(mapOvlay);
    }

    public class MapOverlay extends com.google.android.maps.Overlay {
        private GeoPoint mGpt1;
        private GeoPoint mGpt2;
        protected MapOverlay(GeoPoint gp1, GeoPoint gp2 ) {
            mGpt1 = gp1;
            mGpt2 = gp2;
        }
        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
            super.draw(canvas, mapView, shadow);
            Paint paint;
            paint = new Paint();
            paint.setColor(Color.RED);
            paint.setAntiAlias(true);
            paint.setStyle(Style.STROKE);
            paint.setStrokeWidth(2);
            Point pt1 = new Point();
            Point pt2 = new Point();
            Projection projection = mapView.getProjection();
            projection.toPixels(mGpt1, pt1);
            projection.toPixels(mGpt2, pt2);
            canvas.drawLine(pt1.x, pt1.y, pt2.x, pt2.y, paint);
            return true;
        }
    }
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

这一直让我发疯。我已经寻找了 2 周的解决方案,但一无所获。

4

1 回答 1

2

是否可以像您以错误的顺序将纬度/经度传递给 GeoPoint 构造函数一样简单?您需要先传递纬度,并且基于 -91 不是有效纬度的事实,我猜您的参数已颠倒。

https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/GeoPoint

于 2012-07-21T01:22:03.397 回答