0

我使用了开放的街道地图,但地图没有显示在模拟器上请帮助我做什么/我按照本教程http://www.yousaytoo.com/example-of-implementing-openstreetmap-on-android-using-osmdroid /2807838 并将 jar 文件保存在模拟器上的 lib 文件夹应用程序中,就像这个图像一样,其 url 是http://imgur.com/rLuVk 但地图没有显示在模拟器上请帮助我

这是我下面的所有源代码

    package com.android_osmdroid;

 import org.osmdroid.DefaultResourceProxyImpl;
 import org.osmdroid.ResourceProxy;
 import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;

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

   public class MainActivity extends Activity {

  MyItemizedOverlay myItemizedOverlay = null;

 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    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");

 } 

 }




          package com.android_osmdroid;

        import java.util.ArrayList;

      import org.osmdroid.ResourceProxy;
       import org.osmdroid.api.IMapView;
   import org.osmdroid.util.GeoPoint;
    import org.osmdroid.views.overlay.ItemizedOverlay;
      import org.osmdroid.views.overlay.OverlayItem;

      import android.graphics.Point;
     import android.graphics.drawable.Drawable;

      public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {

        private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();

    public MyItemizedOverlay(Drawable pDefaultMarker,
  ResourceProxy pResourceProxy) {
    super(pDefaultMarker, pResourceProxy);
   // TODO Auto-generated constructor stub
   }

    public void addItem(GeoPoint p, String title, String snippet){
   OverlayItem newItem = new OverlayItem(title, snippet, p);
    overlayItemList.add(newItem);
     populate(); 
   }

  @Override
    public boolean onSnapToItem(int arg0, int arg1, Point arg2, IMapView arg3) {
    // TODO Auto-generated method stub
  return false;
  }

     @Override
   protected OverlayItem createItem(int arg0) {
      // TODO Auto-generated method stub
      return overlayItemList.get(arg0);
     }

     @Override
     public int size() {
 // TODO Auto-generated method stub
     return overlayItemList.size();
     }

 }






        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
    android:layout_height="match_parent" >

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"

    android:text="@string/hello_world"
    tools:context=".MainActivity" />

<org.osmdroid.views.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"/>

     </RelativeLayout>






  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.android_osmdroid"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

      </manifest>
4

2 回答 2

0

您还可以向模拟器设备添加存储以显示地图。否则它只能在硬设备中工作。

于 2013-04-05T13:01:21.903 回答
0

您可以为地图视图设置默认缩放值。你可以看看这个

于 2012-11-29T11:23:19.390 回答