谷歌地图可以工作,但在绘制地理点时会显示gey瓦片



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

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

这让我发疯了。我找了两个星期的解决方案,但一无所获。

这会像你以错误的顺序将lat/lon传递给GeoPoint构造函数这样简单吗?你需要先通过纬度,基于-91不是有效的纬度这一事实,我猜你的参数已经颠倒了。

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

相关内容

  • 没有找到相关文章

最新更新