1

好的,我以前问过这个。得到了一个答案。我将更深入地了解我正在做的事情。我正在为拥有多家商店的企业创建一个应用程序。我有一个布局,显示每个商店的按钮。单击其中一个按钮,它会将您带到另一个带有两个按钮的视图。在这个视图中,有一个按钮,当你点击它时,它会为你调用商店,让它工作得很好。当您单击同一视图中的另一个按钮时,它会将您带到 Google 地图,并向您显示商店的位置。这一切都很好。但我想要的是一个标记也显示在地图上。我不需要它做任何事情,只需向客户展示这是商店所在的位置。这是我正在使用的代码--->

import com.google.android.maps.GeoPoint;

import com.google.android.maps.MapActivity;

import com.google.android.maps.MapController;

import com.google.android.maps.MapView;

import com.google.android.maps.MyLocationOverlay;

import android.os.Bundle;

public class Main extends MapActivity {

    MapController mControl;

    GeoPoint GeoP;

    MapView navView;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        navView = (MapView) findViewById(R.id.navView);

        navView.displayZoomControls(true);

        navView.setBuiltInZoomControls(true);

            navView.setSatellite(true);

            navView.getOverlays().add(new MyLocationOverlay(this,navView));




        double lat = 40.325874;

        double longi = -76.002211;

        GeoP = new GeoPoint((int) ( lat *1E6), (int) (longi * 1E6));

        mControl = navView.getController();

        mControl.animateTo(GeoP);

        mControl.setZoom(20);

        }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;

    }
}
4

3 回答 3

3

@Erik Graul

查看本教程,它将对您有所帮助

http://mobiforge.com/developing/story/using-google-maps-android

于 2012-04-27T04:00:16.373 回答
2

看看这个http://eagle.phys.utk.edu/guidry/android/mapOverlayDemo.htm

于 2012-04-27T05:41:25.070 回答
1
GeoPoint p = mapView.getProjection().fromPixels((int) event.getX(),(int) event.getY());
Drawable srcdrawable = getApplicationContext().getResources().getDrawable(R.drawable.pin_blue);
CustomItemizedOverlay srcitemizedOverlay = new CustomItemizedOverlay(srcdrawable, getApplicationContext());
OverlayItem srcoverlayitem = new OverlayItem(p, "Hello!", "This is your Location.");
srcitemizedOverlay.addOverlay(srcoverlayitem);
mapView.getOverlays().clear();
mapView.getOverlays().add(srcitemizedOverlay);
mapController.animateTo(srcpoint);
mapController.setZoom(16);

在 ontouch 方法中使用上面的代码也使用下面的 CustomItemizedOverlay.java 类

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    private final 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();
    }

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

}
于 2012-04-27T04:44:14.630 回答