如何在默认导航中设置用户当前位置一个Geopoint?

问题描述:

我想设置我的当前位置是默认在我的一个Geopoint。如果我想从我的当前位置获取方向路径到另一个位置,我想在我的一个位置显示默认当前位置。如何在默认导航中设置用户当前位置一个Geopoint?

这是发现用户当前位置的代码:

public class WhereIActivity extends MapActivity{ 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_where_i); 

MapView myMapView=(MapView)findViewById(R.id.myMapView); 

     mapController=myMapView.getController(); 


     myMapView.displayZoomControls(false); 

     mapController.setZoom(17); 


     myMapView.setStreetView(true); 
     myMapView.setTraffic(true); 

LocationManager locationManager; 
     String context = Context.LOCATION_SERVICE; 
     locationManager = (LocationManager)getSystemService(context); 

     Criteria crta = new Criteria(); 
     crta.setAccuracy(Criteria.ACCURACY_FINE); 
     crta.setAltitudeRequired(false); 
     crta.setBearingRequired(false); 
     crta.setCostAllowed(true); 
     crta.setPowerRequirement(Criteria.POWER_LOW); 
     String provider = locationManager.getBestProvider(crta, true); 

    // String provider = LocationManager.GPS_PROVIDER; 
     Location location = locationManager.getLastKnownLocation(provider); 
     updateWithNewLocation(location); 

     locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); 
     } 

private final LocationListener locationListener = new LocationListener() 
    { 

    @Override 
    public void onLocationChanged(Location location) { 
    updateWithNewLocation(location); 
    } 

    @Override 
    public void onProviderDisabled(String provider) { 
    updateWithNewLocation(null); 
    } 

    @Override 
    public void onProviderEnabled(String provider) { 
    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 
    } 

    }; 

private void updateWithNewLocation(Location location) { 
     String latLong; 
     TextView myLocation; 
     myLocation = (TextView) findViewById(R.id.myLocation); 

     String addressString = "no address found"; 

     if(location!=null) { 



      positionOverlay.setLocation(location); 


      Double geoLat=location.getLatitude()*1E6; 
      Double geoLng=location.getLongitude()*1E6; 
      GeoPoint point=new GeoPoint(geoLat.intValue(),geoLng.intValue()); 

      mapController.animateTo(point); 

     double lat = location.getLatitude(); 
     double lon = location.getLongitude(); 
     latLong = "Lat:" + lat + "\nLong:" + lon; 

double lattitude = location.getLatitude(); 
     double longitude = location.getLongitude(); 

     Geocoder gc = new Geocoder(this,Locale.getDefault()); 
     try { 
     List<Address> addresses= gc.getFromLocation(lattitude, longitude, 1); 
     StringBuilder sb = new StringBuilder(); 
     if(addresses.size()>0) { 
     Address address=addresses.get(0); 
     for(int i=0;i<address.getMaxAddressLineIndex();i++) 
      sb.append(address.getAddressLine(i)).append("\n"); 
     sb.append(address.getLocality()).append("\n"); 
     sb.append(address.getPostalCode()).append("\n"); 
    sb.append(address.getCountryName()); 
    } 
     addressString = sb.toString(); 
     } 
     catch (Exception e) { 
     } 
     } else { 
     latLong = " NO Location Found "; 
     } 

     myLocation.setText("Your Current Position is :\n"+ latLong + "\n"+ addressString); 
    } 

@Override 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 
    } 

如何设置方向路径该用户当前的位置默认:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
       Uri.parse("http://maps.google.com/maps/?daddr=my+street+address")); 
       intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); 
       startActivity(intent); 

请仔细阅读本链接。这段代码成功运行在我的应用程序

http://ckpatel.blog.com/category/android-gps/

该代码可用于绘制路径,我认为获取地点的代码是正确的,但在移动设备进行检查。谢谢