0

我正在做我的毕业论文,我必须做一个 Android 应用程序,在谷歌地图上显示我的位置(我已经做过),当我靠近大学内的某些地方时,会弹出一些建筑物的信息(我可能会通过接近警报来做到这一点)。关键是我想将它们将在地图上显示的地方作为文本文件中的图钉导入。

这可能吗(我已经做到了,但在代码内部是静态的)?我正在研究 Eclipse,如果有用,我可以复制/粘贴代码。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    Drawable marker=getResources().getDrawable(R.drawable.pushpin);
    marker.setBounds((int) (-marker.getIntrinsicWidth()/2),-marker.getIntrinsicHeight(),(int) (marker.getIntrinsicWidth()/2),0);        
    mapController=mapView.getController();
    mapController.setZoom(15);

    InterestingLocations funPlaces= new InterestingLocations(marker);
    mapView.getOverlays().add(funPlaces);

    GeoPoint pt=funPlaces.getCenterPt();
    int latSpan=funPlaces.getLatSpanE6();
    int lonSpan=funPlaces.getLonSpanE6();
    Log.v("Overlays", "Lat span is " + latSpan);
    Log.v("Overlays", "Lon span is " + lonSpan);

    MapController mc = mapView.getController();
    mc.setCenter(pt);
    mc.zoomToSpan((int) (latSpan*1.5), (int)(lonSpan*1.5));


    whereAmI= new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(whereAmI);
    mapView.postInvalidate();

public class InterestingLocations extends ItemizedOverlay{
    private ArrayList<OverlayItem> locations = new ArrayList<OverlayItem>();
    private GeoPoint center=null;

    public InterestingLocations(Drawable marker){
        super(marker);

        GeoPoint disneyMagicKingdom = new GeoPoint((int)(37.97897823618044*1000000) ,(int)(23.6723855137825*1000000));
        GeoPoint disneySevenLagon= new GeoPoint((int)(37.98013047446126*1000000) ,(int)(13.6715030670166*1000000));
        locations.add(new OverlayItem(disneyMagicKingdom,"Magic Kingdom","Magic Kingdom"));
        locations.add(new OverlayItem(disneySevenLagon,"Seven Lagon","Seven Lagon"));

        populate();
    }
4

1 回答 1

0

是的,你可以做到。将文本文件保存在资源的资产文件夹中。从中读取位置并在加载时在地图上放置一个覆盖(该位置的引脚)。如果您需要一个教程来开始使用谷歌地图,那么是一个很好的教程。

于 2013-01-07T08:02:35.050 回答