Reputation: 25
I am developing an Android application. I need to locate the user. So I want to use Google OpenStreetMap. I want to integrate the open street view to my application, but when the application starts, the map is not loaded. Instead I get only a marker. Here is my code:
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();
}
}
Thank you for your help.
Upvotes: 1
Views: 447
Reputation: 21469
You didn't set a tile source. Please call setTileSource()
on your MapView
object appropriately.
And please don't mix up terms, there is no "google open street maps". The project is called OpenStreetMap (without a s at the end) and Google is not involved at all.
Upvotes: 1