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);
}
}
**
//私のコードは一度調べて助けてくれます...私は多くのブログを見てきましたが、私のコードに適したアプリケーションを見つけることができませんでした。 Implect インテントを使用して、電話でデフォルト マップを呼び出すだけです。マップ ビューではなく、電話でデフォルトのマップを使用しています
**