public class Menuutama extends Activity {
//------------ GPS --------------------------------------------------------- //
String myLati = "-6.353370";
String myLongi = "106.832349";
String myPosisi = "Lp2m aray Jkt";
//------------ GPS Defaulde ------------------------------------------------ //
//------------Button GPS --------------------------------------------------- //
ImageView btnAnggota = (ImageView) findViewById(R.id.btnAnggota);
btnAnggota.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View arg0) {
Intent i = new Intent(getApplicationContext(), List_anggota.class);
i.putExtra("pk", myLati);
i.putExtra("pk", myLongi);
i.putExtra("pk", myPosisi);
startActivityForResult(i, 100); }});
//------------Button GPS --------------------------------------------------- //
Dibawah :
ImageView btnKeluar = (ImageView) findViewById(R.id.btnKeluar);
btnKeluar.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View arg0) { keluarYN(); } });
//------------ GPS --------------------------------------------------------- //
LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager) getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling // Activity#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for Activity#requestPermissions for more details. return;
}
Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 2000, 10,
locationListener);
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};
private void updateWithNewLocation(Location location) {
double latitude=Double.parseDouble(myLati);
double longitude=Double.parseDouble(myLongi);
String addressString = "No address found";
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
Geocoder gc = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocation(latitude, longitude, 1);
StringBuilder sb = new StringBuilder();
if (((List) addresses).size() > 0) {
Address address = addresses.get(0);
for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
} catch (IOException e) {}
} else {
myLati="-6.353370";
myLongi="106.832349";
addressString="Lp2m Aray Jkt";
}
myPosisi=addressString;
myLati=String.valueOf(latitude);
myLongi=String.valueOf(longitude);
TextView txtMarquee=(TextView)findViewById(R.id.txtMarquee);
txtMarquee.setSelected(true);
String kata="Posisi Anda :"+myLati+"/"+myLongi+" "+myPosisi+"#";
String kalimat=String.format("%1$s", TextUtils.htmlEncode(kata));
txtMarquee.setText(Html.fromHtml(kalimat+kalimat+kalimat));
}
//------------ GPS -------------------------------------------------------------- //
Diatas ===
public void keluar(){
No comments:
Post a Comment