2011-04-18 85 views
1
package com.geoo; 

import android.app.Activity; 
import android.content.Context; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.widget.Toast; 

public class localisation extends ActivityBase{ 

/** Called when the activity is first created. */ 

@Override 

public void onCreate(Bundle savedInstanceState){ 

super.onCreate(savedInstanceState); 
setContentView(R.layout.localisation); 

/* Use the LocationManager class to obtain GPS locations */ 

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 

LocationListener mlocListener = new MyLocationListener(); 

mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener); 

} 

/* Class My Location Listener */ 

public class MyLocationListener implements LocationListener 

{ 

@Override 

public void onLocationChanged(Location loc) 

{ 

loc.getLatitude(); 

loc.getLongitude(); 

String Text = "My current location is: " + "Latitud = " + loc.getLatitude()+ "Longitud = " + loc.getLongitude(); 
Toast.makeText(getApplicationContext(),Text, Toast.LENGTH_SHORT).show(); 
} 

@Override 

public void onProviderDisabled(String provider) 
{ 
Toast.makeText(getApplicationContext(),"Gps Disabled",Toast.LENGTH_SHORT).show(); 
} 

@Override 

public void onProviderEnabled(String provider) 
{ 
Toast.makeText(getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show(); 
} 

@Override 

public void onStatusChanged(String provider, int status, Bundle extras) 

{ 
} 
}/* End of Class MyLocationListener */ 

}/* End of UseGps Activity */ 

現在我wanf添加地圖和標記添加谷歌地圖到我的應用程序和標記

import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapView; 
import com.google.android.maps.MapView.LayoutParams; 
添加MapView的main.xml中

<com.google.android.maps.MapView 
     android:id="@+id/mapview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:clickable="true" 
     android:apiKey="Your Maps API Key" 
    /> 

許多錯誤

hox我可以修復這些問題

我閱讀了很多文件,但我沒有理由,我怎麼能做到這一點。

謝謝

+0

你使用Eclipse?如果是這樣,發佈Logcat輸出。否則,發佈一些錯誤信息,供所有人查看。另外,您的類「本地化」需要擴展MapActivity,而不是ActivityBase。 – apesa 2011-04-18 17:06:31

回答

3

有關的MapView的setContentView(R.layout.localisation)一個很好的教程;應該以包含mapview - > setContentView(R.layout.main)的xml資源命名。

,對於該標記請參閱開發者教程,但在全球的步驟,讓您的想法:

1-製成定製覆蓋

2-獲得通過調用MapView.getOverlays的mapOverlay();

3 - 讓你的customoverlay的實例

4-添加OverlayItems這個customoverlay

5 - 這customoverlay添加到mapoverlay

那些步驟

2

首先你需要一個地圖API密鑰,以便開始HERE然後,你需要實際使用的MapView,在你的XML,你需要的setContentView符合規範的MapView這樣。

public void onCreate(Bundle savedInstanceState){ 

super.onCreate(savedInstanceState); 
setContentView(R.layout.mapview); 

要使用位置管理器在地圖上放置標記,您可以使用ItemizedOverlay。您還需要在您的Manifest XML中爲GPS位置設置訪問權限。確保訪問許可標籤在應用程序標籤之外。

​​

最後,這裏是你應該引用Google Map View

2

代替

public class localisation extends ActivityBase 

嘗試使用

public class localisation extends MapActivity 

這會幫助你消除這些錯誤

相關問題