how to get your current position in android and draw the path or line between your current position and the location that you That Is Touched.
Asked
Active
Viewed 607 times
-2
-
Do you have problems retrieving user's location? – Axarydax Apr 01 '13 at 12:09
1 Answers
1
To know your current location you require to get the latitude and longitude of your current 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);
}
After that use a marker
https://developers.google.com/maps/documentation/android/marker.
You require latitude and longitude of your destination.
https://developers.google.com/maps/documentation/android/shapes#polylines.
Use polylines to draw path from your location to the destination
Answer : Draw path between two points using Google Maps Android API v2. This link has a good explanation on the topic.

Community
- 1
- 1

Raghunandan
- 132,755
- 26
- 225
- 256