Skip to content

Instantly share code, notes, and snippets.

@omayib
Created November 24, 2012 03:01
Show Gist options
  • Save omayib/4138198 to your computer and use it in GitHub Desktop.
Save omayib/4138198 to your computer and use it in GitHub Desktop.
Pengenalan GPS
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lonText"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/longitutdeTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/unk" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/latText"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/latitudeTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/unk" >
</TextView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gps.sederhana"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
</uses-permission>
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<activity
android:name=".LokasikuActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
package com.gps.sederhana;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class LokasikuActivity extends Activity {
TextView latTxt, lonTxt;
LocationManager lm;
LocationListener locListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
latTxt = (TextView) findViewById(R.id.latitudeTxt);
lonTxt = (TextView) findViewById(R.id.longitutdeTxt);
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locListener = new MyLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 10,
locListener);
}
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
// TODO Auto-generated method stub
if (loc != null) {
latTxt.setText(String.valueOf(loc.getLatitude()));
lonTxt.setText(String.valueOf(loc.getLongitude()));
Toast.makeText(
getBaseContext(),
"Location Changed : Lat " + loc.getLatitude() +
"lgt: " + loc.getLongitude(), Toast.LENGTH_SHORT)
.show();
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
@hakz
Copy link

hakz commented Nov 24, 2012

lanjut om :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment