0

このコードを使用して、ユーザーの現在の場所を表示しています。でもマーカーもつけなきゃいけない。これに関するいくつかのチュートリアルをすでに見ましたが、まだわかりません。

これが私のアクティビティです

public class MapViewActivity extends MapActivity {
    @Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub
        super.onCreate(arg0);
        setContentView(R.layout.mapview);


//------------Start Displaying Map View--------------//     
     LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

            LocationListener locationListener = new LocationListener() {
                public void onLocationChanged(Location location) {
                    int lat = (int) (location.getLatitude() * 1E6);
                    int lng = (int) (location.getLongitude() * 1E6);
                    GeoPoint test= new GeoPoint(
                            lat,lng);

                   MapView mapview = (MapView) findViewById(R.id.mvmap);
                   MapController mapcontrol = mapview.getController();
                   mapcontrol.animateTo(test);
                   mapcontrol.setZoom(10);
                   mapview.setStreetView(true);
                   mapview.setSatellite(true);
                   mapview.setBuiltInZoomControls(true);
                }


                public void onProviderDisabled(String provider) {
                    // TODO Auto-generated method stub

                }

                public void onProviderEnabled(String provider) {
                    // TODO Auto-generated method stub

                }

                public void onStatusChanged(String provider, int status, Bundle extras) {
                    // TODO Auto-generated method stub

                }
            };
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
4

1 に答える 1

1

このクラスを ItemizedOverlay に使用します。

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {

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

private Context context;

public CustomItemizedOverlay(Drawable defaultMarker) {
    super(boundCenterBottom(defaultMarker));
}

public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
    this(defaultMarker);
    this.context = context;
}

@Override
protected OverlayItem createItem(int i) {
    return mapOverlays.get(i);
}

@Override
public int size() {
    return mapOverlays.size();
}

@Override
protected boolean onTap(int index) {
    OverlayItem item = mapOverlays.get(index);
    Log.e(" on tap item value ", "" + mapOverlays.get(index) + " Index "
            + index);
    AlertDialog.Builder dialog = new AlertDialog.Builder(context);
    dialog.setTitle(item.getTitle());
    dialog.setMessage(item.getSnippet());
    dialog.show();

    return true;
}

public void addOverlay(OverlayItem overlay) {
    mapOverlays.add(overlay);
    this.populate();
}

public void removeOverlay() {
    mapOverlays.clear();
    // this.populate();
}

}

MapViewActivity で、宣言します。

 CustomItemizedOverlay itemizedOverlay;
List<Overlay> mapOverlays;

mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new CustomItemizedOverlay(drawable, this);


OverlayItem overlayitem = new OverlayItem(test," "," ");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
于 2012-08-06T08:31:10.790 に答える