如何在谷歌地图上固定位置点击位置

时间:2012-03-04 11:11:37

标签: android google-maps bitmap

我第一次尝试谷歌地图时,我从From this site获得了一些教程

我们可以固定一个位置,但是在点击代码时没有显示针脚的特定位置

public class GoogleActivity extends MapActivity 
{    
    MapView mapView; 
    MapController mc;
    GeoPoint p;

class MapOverlay extends com.google.android.maps.Overlay
{


    @Override
    public boolean draw(Canvas canvas, MapView mapView, 
    boolean shadow, long when) 
    {
        super.draw(canvas, mapView, shadow);                   

        //---translate the GeoPoint to screen pixels---
        Point screenPts = new Point();
        mapView.getProjection().toPixels(p, screenPts);

        //---add the marker---
        Bitmap bmp = BitmapFactory.decodeResource(
            getResources(), R.drawable.ic_launcher);            
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
        return true;
    }
} 

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

    mapView = (MapView) findViewById(R.id.mapView);
    LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
    View zoomView = mapView.getZoomControls(); 



    zoomLayout.addView(zoomView, 
        new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, 
            LayoutParams.WRAP_CONTENT)); 
    mapView.displayZoomControls(true);

    mc = mapView.getController();
    String coordinates[] = {"1.352566007", "103.78921587"};
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);

    p = new GeoPoint(
        (int) (lat * 1E6), 
        (int) (lng * 1E6));

    mc.animateTo(p);
    mc.setZoom(17); 
    mapView.invalidate();


     //---Add a location marker---
     MapOverlay mapOverlay = new MapOverlay();
     List<Overlay> listOfOverlays = mapView.getOverlays();
     listOfOverlays.clear();
     listOfOverlays.add(mapOverlay);        

     mapView.invalidate();
}

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

现在我需要的是,当我小鸡某个特定位置时,我想要固定一个位置。如何在谷歌地图中实现点击事件

1 个答案:

答案 0 :(得分:2)

MapOverlay类有一个onTap()方法可以覆盖。当您在地图上选项卡时将调用它,并且GeoPoint对象将作为描述录制位置的参数传递。