gohan0189
28/02/12, 21:12:57
hola
regreso con un tema de gps ya que necesito que al dar click a mi boton muestre mi ubicacion ya me salen los mapas de google pero no me muestra donde estoy ya que no se como reaizar 4esto alguien me puede ayudar?? este es mi codigo
public class GoogleMaps extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.gps);
MapView mapView =(MapView) findViewById (R.id.map_view);
mapView.setBuiltInZoomControls(true);
LocationManager locationManager = (LocationManager) getSystemService (Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates (LocationManager.GPS_PROVIDER,6000,50,
new Location (mapView.getController(),locationManager,getBaseCo ntext()));
mapView.setBuiltInZoomControls(true);
}
@Override
protected boolean isRouteDisplayed()
{
return false;
}
}
public class Location implements LocationListener {
private Context context;
private LocationManager locationManager;
private MapController mapController;
public Location (MapController mapController, LocationManager locationManager, Context context)
{
this.mapController = mapController;
this.locationManager= locationManager;
this.context = context;
}
@Override
public void onLocationChanged (android.location.Location loc) {
Toast.makeText(context, "onLocationChanged",Toast.LENGTH_SHORT).show();
if(loc!=null) {
Toast.makeText(context,
"Location changed : Lat: "+loc.getLatitude()+ "Lng: " + loc.getLongitude(), Toast.LENGTH_SHORT).show();
GeoPoint p =new GeoPoint (
(int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude()* 1E6));
mapController.animateTo (p);
mapController.setZoom (12);
}
else
{
Toast.makeText(context,"location changed to null value", Toast.LENGTH_SHORT).show ();
}
//por el emulador ??
locationManager.removeUpdates (this);
locationManager.requestLocationUpdates(LocationMan ager.GPS_PROVIDER,0,0,
new Location (mapController, locationManager, context));
}
@Override
public void onProviderDisabled (String arg0) {
Toast.makeText(context,"Provider Disabled",
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String arg0){
Toast.makeText(context, "Provider Enabled",
Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle arg2) {
Toast.makeText(context, "Status on " + provider + " is " + getStatusMessage(status),
Toast.LENGTH_SHORT).show();
}
private String getStatusMessage (int status) {
//TODO Auto-generated method stub
if (status ==1)
return "contecting";
else if (status ==2)
return "conected";
return "unknown";
}
}
regreso con un tema de gps ya que necesito que al dar click a mi boton muestre mi ubicacion ya me salen los mapas de google pero no me muestra donde estoy ya que no se como reaizar 4esto alguien me puede ayudar?? este es mi codigo
public class GoogleMaps extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.gps);
MapView mapView =(MapView) findViewById (R.id.map_view);
mapView.setBuiltInZoomControls(true);
LocationManager locationManager = (LocationManager) getSystemService (Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates (LocationManager.GPS_PROVIDER,6000,50,
new Location (mapView.getController(),locationManager,getBaseCo ntext()));
mapView.setBuiltInZoomControls(true);
}
@Override
protected boolean isRouteDisplayed()
{
return false;
}
}
public class Location implements LocationListener {
private Context context;
private LocationManager locationManager;
private MapController mapController;
public Location (MapController mapController, LocationManager locationManager, Context context)
{
this.mapController = mapController;
this.locationManager= locationManager;
this.context = context;
}
@Override
public void onLocationChanged (android.location.Location loc) {
Toast.makeText(context, "onLocationChanged",Toast.LENGTH_SHORT).show();
if(loc!=null) {
Toast.makeText(context,
"Location changed : Lat: "+loc.getLatitude()+ "Lng: " + loc.getLongitude(), Toast.LENGTH_SHORT).show();
GeoPoint p =new GeoPoint (
(int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude()* 1E6));
mapController.animateTo (p);
mapController.setZoom (12);
}
else
{
Toast.makeText(context,"location changed to null value", Toast.LENGTH_SHORT).show ();
}
//por el emulador ??
locationManager.removeUpdates (this);
locationManager.requestLocationUpdates(LocationMan ager.GPS_PROVIDER,0,0,
new Location (mapController, locationManager, context));
}
@Override
public void onProviderDisabled (String arg0) {
Toast.makeText(context,"Provider Disabled",
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String arg0){
Toast.makeText(context, "Provider Enabled",
Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle arg2) {
Toast.makeText(context, "Status on " + provider + " is " + getStatusMessage(status),
Toast.LENGTH_SHORT).show();
}
private String getStatusMessage (int status) {
//TODO Auto-generated method stub
if (status ==1)
return "contecting";
else if (status ==2)
return "conected";
return "unknown";
}
}