2013-04-01 211 views

回答

1

要知道您當前的位置,您需要獲取當前loacation的經緯度。

public void getLatiLongi() 
{ 
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
     if (location != null) { 
       flati = location.getLatitude(); 
       flongi = location.getLongitude(); 
       System.out.println("Hello....................+lati+longi"); 
      } 
    } 

    @Override 
    protected void onStart() { 
     super.onStart(); 

     LocationManager locationManager = 
       (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 

     if (!gpsEnabled) { 
      gpsAlert(); 

     } 
    } 

    public void gpsAlert(){ 
     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); 

      alertDialogBuilder.setTitle("Enable GPS"); 
      alertDialogBuilder 
       .setMessage("Yes")  
       .setCancelable(false) 
       .setPositiveButton("Yes",new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog,int id) { 

         enableLocationSettings(); 
         dialog.cancel(); 
        } 
        }) 
       .setNegativeButton("No",new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog,int id) {   
         dialog.cancel(); 
        } 
       }); 
       AlertDialog alertDialog = alertDialogBuilder.create(); 
       alertDialog.show(); 
    } 
    private void enableLocationSettings() { 
     Intent settingsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
     startActivity(settingsIntent); 
    } 

之後使用標記

https://developers.google.com/maps/documentation/android/marker

你需要你的目的地的經度和緯度。

https://developers.google.com/maps/documentation/android/shapes#polylines

使用折線從您的位置繪製路徑到目的地

Answer : Draw path between two points using Google Maps Android API v2。這個鏈接對這個話題有很好的解釋。

+0

thx我要去試試看 –

相關問題