import android.location.GpsStatus;
import android.location.GpsStatus.Listener;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
@SuppressLint("NewApi")
public class SpaLocationActivity extends Activity implements LocationListener {
protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
TextView txtLat;
String lat;
String provider;
double latitude;
protected double longitude;
protected boolean gps_enabled,network_enabled;
Intent mapIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spa_location);
txtLat = (TextView) findViewById(R.id.textView1);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null);
Location location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
txtLat = (TextView) findViewById(R.id.textView1);
txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());
latitude=location.getLatitude();
longitude=location.getLongitude();
Uri locationUri = Uri.parse("geo:"+latitude+","+longitude+"?z=14");
mapIntent = new Intent(Intent.ACTION_VIEW, locationUri);
}
@Override
public void onLocationChanged(Location location) {
//txtLat = (TextView) findViewById(R.id.textView1);
//txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());
}
@Override
public void onProviderDisabled(String provider) {
Log.d("Latitude","disable");
}
@Override
public void onProviderEnabled(String provider) {
Log.d("Latitude","enable");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Latitude","status");
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
locationManager.removeUpdates(locationListener);
// locationManager.removeGpsStatusListener((Listener) locationListener);
// locationManager.removeNmeaListener(listener)
}
public void openMap(View view){
startActivity(mapIntent);
}
}
**
//这是我的代码检查一次并帮助我...我看过很多博客,但没有为我的代码找到合适的应用程序。我看过很多帖子,如果使用 mapview 和 MyLocationOverlay 是可能的,但我是只需使用隐含意图并在手机上调用默认地图。我在手机中使用默认地图而不是地图视图
**