| 
目前的功能可以跟隨位置作出定位但不知道要如何在螢幕上顯示出經緯度
x
馬上加入Android 台灣中文網,立即免費下載應用遊戲。您需要 登錄 才可以下載或查看,沒有帳號?註冊  請各位大大幫忙
 
 
 
 public class Navigation extends MapActivity implements LocationListener  {                  private MapView MV;         private TextView tvLat;         private TextView tvLong;                  private LocationManager locationManager;         private MapController mapController;         private MyLocationOverlay LocOver;         private boolean enableTool;          
     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.navigation); 
         findControl();     } 
     //偵測GPS是否開啓     private void init()         {             if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))             { 
                 new AlertDialog.Builder(Navigation.this).setTitle("地圖工具").setMessage("您尚未開啟定位服務,要前往設定頁面啟動定位服務嗎?")                         .setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener()                         {                             public void onClick(DialogInterface dialog, int which)                             {                                 startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));                             }                         }).setNegativeButton("Cancel", new DialogInterface.OnClickListener()                         {                             public void onClick(DialogInterface dialog, int which)                             {                                 Toast.makeText(Navigation.this, "未開啟定位服務,無法使用本工具!!", Toast.LENGTH_SHORT).show();                             }                         }).show();             }             else             {                 enableMyLocation();                 enableTool = true;             }         } 
         private void findControl() {                 MV = (MapView) findViewById(R.id.mv);                 MV.setBuiltInZoomControls(true);                 TextView tvlong = (TextView)findViewById(R.id.tvLong);                 TextView tvlat = (TextView)findViewById(R.id.tvLat);                         mapController = MV.getController();                         //顯示畫面大小                         mapController.setZoom(16);                         locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);                         //WI-FI定位                         locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, Navigation.this);                         //GPS定位                         locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, Navigation.this);                              /*                                 //取得緯度                         LocOver.getMyLocation().getLatitudeE6();                         //取的經度                         LocOver.getMyLocation().getLongitudeE6();                */ 
         }          
         private void enableMyLocation()             {                 // 定位點                 List<Overlay> overlays = MV.getOverlays();                 LocOver = new MyLocationOverlay(this, MV);                 LocOver.enableCompass();                 LocOver.enableMyLocation(); 
 /*                //取得緯度                 LocOver.getMyLocation().getLatitudeE6();                 //取的經度                 LocOver.getMyLocation().getLongitudeE6();                */ 
                 LocOver.runOnFirstFix(new Runnable()                 {                     public void run()                     {                         mapController.animateTo(LocOver.getMyLocation());                                              }                 });                 overlays.add(LocOver);             }                  @Override             protected void onResume()             {                 super.onResume();                 if (enableTool)                 {                     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, Navigation.this);                     locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, Navigation.this);                      
                     LocOver.enableMyLocation();                     LocOver.enableCompass();                      
                 }                 else                 {                     init();                 }             }                 
         @Override             protected void onPause()             {                 super.onPause();                 if (enableTool)                 {                     locationManager.removeUpdates(Navigation.this);                     LocOver.disableCompass();                     LocOver.disableMyLocation();                 }             } 
 
         @Override                  //當地點改變時         public void onLocationChanged(Location location) {                 // TODO Auto-generated method stub                          } 
         @Override         //當GPS或網路定位功能關閉時         public void onProviderDisabled(String provider) {                 // TODO Auto-generated method stub                          } 
 
         @Override         //當GPS或網路定位功能開啟         public void onProviderEnabled(String provider) {                 // TODO Auto-generated method stub                          } 
 
         @Override         //定位狀態改變         public void onStatusChanged(String provider, int status, Bundle extras) {                 // TODO Auto-generated method stub                          } 
 
         @Override         protected boolean isRouteDisplayed() {                 // TODO Auto-generated method stub                 return false;         } 
 } 
 |