Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.geolocat;
- import org.w3c.dom.Text;
- import com.google.android.maps.GeoPoint;
- import android.R.string;
- 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.view.Menu;
- import android.view.MenuItem;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends Activity {
- TextView textLat;
- TextView textLong;
- GeoPoint geopoint;
- TextView tampil;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- textLat =(TextView)findViewById(R.id.textLat);
- textLong=(TextView)findViewById(R.id.textLong);
- LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
- LocationListener ll = new mylocation();
- lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 2, ll);
- }
- class mylocation implements LocationListener {
- @Override
- public void onLocationChanged(Location location) {
- if(location != null){
- double plong = location.getLongitude();
- double plat = location.getLatitude();
- double plong2 = location.getLongitude();
- double plat2 = location.getLatitude();
- // maksudnya mau biar setiap location baru dia get coordinate trus langsung hitung gitu pak, ada ide gak? hehehe
- // Location locationA = new Location("point A");
- // locationA.setLatitude(plat);
- // locationA.setLongitude(plong);
- // Location locationB = new Location("Point B");
- // locationB.setLongitude(plong2);
- // locationB.setLatitude(plat2);
- // float distance = locationA.distanceTo(locationB);
- // tampil.setText(Float.toString(distance));
- textLat.setText(Double.toString(plat));
- textLong.setText(Double.toString(plong));
- }
- }
- @Override
- public void onStatusChanged(String provider, int status, Bundle extras) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onProviderEnabled(String provider) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onProviderDisabled(String provider) {
- // TODO Auto-generated method stub
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement