Android OpenStreetMap显示标记而不是地图

时间:2015-04-14 23:10:52

标签: android maps openstreetmap osmdroid

我正在开发一个Android应用程序。我需要找到用户。所以我想使用Google OpenStreetMap。我想将打开的街道视图集成到我的应用程序中,但是当应用程序启动时,不会加载地图。相反,我只得到一个标记。这是我的代码:

import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.MyLocationOverlay;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

public class MainActivity extends Activity {

    MyItemizedOverlay myItemizedOverlay = null;
    MyLocationOverlay myLocationOverlay = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MapView mapView = (MapView) findViewById(R.id.button1);
        mapView.setBuiltInZoomControls(true);

        Drawable marker = getResources().getDrawable(
                android.R.drawable.star_big_on);
        int markerWidth = marker.getIntrinsicWidth();
        int markerHeight = marker.getIntrinsicHeight();
        marker.setBounds(0, markerHeight, markerWidth, 0);

        ResourceProxy resourceProxy = new DefaultResourceProxyImpl(
                getApplicationContext());

        myItemizedOverlay = new MyItemizedOverlay(marker, resourceProxy);
        mapView.getOverlays().add(myItemizedOverlay);

        GeoPoint myPoint1 = new GeoPoint(0 * 1000000, 0 * 1000000);
        myItemizedOverlay.addItem(myPoint1, "myPoint1", "myPoint1");
        GeoPoint myPoint2 = new GeoPoint(50 * 1000000, 50 * 1000000);
        myItemizedOverlay.addItem(myPoint2, "myPoint2", "myPoint2");

        myLocationOverlay = new MyLocationOverlay(this, mapView);
        mapView.getOverlays(`enter code here`).add(myLocationOverlay);
        myLocationOverlay.enableMyLocation();    
    }
} 

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您没有设置磁贴源。请恰当地致电setTileSource()对象上的MapView

请不要混淆条款,没有“谷歌开放街道地图”。该项目名为OpenStreetMap(最后没有 s ),谷歌根本不参与。