如何添加推针

时间:2010-10-08 23:57:31

标签: java android eclipse google-maps

我已经根据本教程Here

创建了一个地图

但无论我做什么,我都无法添加推针,当我到达这里时“要向地图添加标记,首先需要定义一个扩展Overlay类的类:”

我遇到困难,我试图在Android开发者的HelloGoogleMaps教程之后添加一个MapOverlay来添加叠加层但是我到处都有错误,有人指向正确的方向或建议一个tutrorial或提供一个链接到可能有帮助的源代码,我的代码如下;

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.MapView.LayoutParams;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

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

    /** 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[] = {" 53.804224", "-1.759057"};
        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();
        mapView.setSatellite(true);
    }

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

此时,当我尝试在HelloGoogleMaps教程中添加mapoverlay时,它会崩溃或我收到错误。

提前致谢

0 个答案:

没有答案