2013-01-07 40 views
0

我正在做我的畢業論文,我必須做一個Android應用程序,它顯示我在谷歌地圖上的位置(我已經完成了),當我接近大學內的一些地方會彈出一些關於建築物的信息(我可能會用接近警報來做這件事)。重點是,我想導入他們將顯示在地圖上的地方作爲一個文本文件的pin。從文本文件導入座標在谷歌地圖上銷釘android gps

這是可能的(我已經做到了,但從代碼中靜態)?我正在使用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(); 
    } 

回答

0

是的,你可以做到這一點。將文本文件保存在資源的資產文件夾中。從中讀取位置並在加載時在地圖上放置覆蓋圖(該位置的圖釘)。如果您需要教程才能開始使用Google地圖,那麼here是一個不錯的選擇。

+0

鏈接不工作我會等待閱讀文章。以上是我的代碼看看,如果你想。 – Panos

+0

當我發佈時,它正在工作。可能是網站服務器關閉。在某個時間後嘗試。 我認爲你的代碼看起來不錯。只需將地點詳情保存在「res」資產文件夾中的文本文件中即可。閱讀並解析每個位置,並放置一個逐項疊加,就像您現在正在做的那樣。 – SKK

+0

如何清楚第一個座標在文本文件中的開始和結束位置? – Panos