I want to display my current location, but it shows me the latitude and longitude that I set on the command line! If I don't set the parameters on the command line, this will show me the latitude and longitude included in Eclipse!
Does anyone have an idea? I am testing AVD.
I did a test to find out if my location is turned on, but it’s not. I do not know why this is so.
This is my code:
package com.manita.mapuse; import java.io.InputStream; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.widget.Toast; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import com.google.android.maps.MyLocationOverlay; public class MapuseActivity extends MapActivity implements LocationListener { private MapView mapView = null; private LocationManager lm = null; private double lat = 0; private double lng = 0; private double alt = 0; private MapController mc = null; private MyLocationOverlay myLocation = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) this.findViewById(R.id.mapView); mapView.setBuiltInZoomControls(true); lm = (LocationManager) this.getSystemService(LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, this); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, this); mc = mapView.getController(); mc.setZoom(10); myLocation = new MyLocationOverlay(getApplicationContext(), mapView); myLocation.runOnFirstFix(new Runnable() { public void run() { mc.animateTo(myLocation.getMyLocation()); mc.setZoom(10); } }); LocationManager locationManager; String context = Context.LOCATION_SERVICE; locationManager = (LocationManager)getSystemService(context); String provider = LocationManager.GPS_PROVIDER; lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, this); Location location = locationManager.getLastKnownLocation(provider); locationManager.getProvider(provider); if(!locationManager.isProviderEnabled(provider)){ locationManager.setTestProviderEnabled(provider, true); } boolean enabled = locationManager.isProviderEnabled(provider); if(enabled){ Toast.makeText(getBaseContext(), "provide enabled : Latitude = " + lat + " Longitude = " + lng+" Altitude = " + alt, Toast.LENGTH_SHORT).show(); } else{ Toast.makeText(getBaseContext(), "provider disabled : Latitude = " + lat + " Longitude = " + lng+" Altitude = " + alt, Toast.LENGTH_SHORT).show(); } if(location!=null){ lat = location.getLatitude(); lng = location.getLongitude(); alt = location.getAltitude(); Toast.makeText(getBaseContext(), "providerrr enabled : Latitude = " + lat + " Longitude = " + lng+" Altitude = " + alt, Toast.LENGTH_SHORT).show(); } else{ Toast.makeText(getBaseContext(), "location not found : Latitude = " + lat + " Longitude = " + lng+" Altitude = " + alt, Toast.LENGTH_SHORT).show(); } mapView.getOverlays().add(myLocation); if (myLocation.isMyLocationEnabled()!=false) { GeoPoint p =myLocation.getMyLocation(); lat= p.getLatitudeE6(); lng= p.getLongitudeE6(); alt = location.getAltitude(); Toast.makeText(getBaseContext(), "geolocalisation activé lat: "+lat+ " long: " +lng +" Altitude = " + alt, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getBaseContext(), "geolocalisation desactivée" , Toast.LENGTH_SHORT).show(); }
Thanks!
source share