Advertisement
denis212

MainActivity

Nov 27th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.93 KB | None | 0 0
  1. package com.geolocat;
  2.  
  3. import org.w3c.dom.Text;
  4.  
  5. import com.google.android.maps.GeoPoint;
  6.  
  7. import android.R.string;
  8. import android.app.Activity;
  9. import android.content.Context;
  10. import android.location.Location;
  11. import android.location.LocationListener;
  12. import android.location.LocationManager;
  13. import android.os.Bundle;
  14. import android.view.Menu;
  15. import android.view.MenuItem;
  16. import android.widget.TextView;
  17. import android.widget.Toast;
  18.  
  19. public class MainActivity extends Activity {
  20.  
  21.     TextView textLat;
  22.     TextView textLong;
  23.     GeoPoint geopoint;
  24.     TextView tampil;
  25.    
  26.    
  27.    
  28.     @Override
  29.     protected void onCreate(Bundle savedInstanceState) {
  30.         super.onCreate(savedInstanceState);
  31.         setContentView(R.layout.activity_main);
  32.        
  33.         textLat =(TextView)findViewById(R.id.textLat);
  34.         textLong=(TextView)findViewById(R.id.textLong);
  35.        
  36.         LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  37.         LocationListener ll = new mylocation();
  38.         lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 2, ll);
  39.        
  40.        
  41.        
  42.     }
  43.  
  44.      class mylocation implements LocationListener {
  45.         @Override
  46.         public void onLocationChanged(Location location) {
  47.        
  48.             if(location != null){
  49.                
  50.                 double plong = location.getLongitude();
  51.                 double plat = location.getLatitude();
  52.                 double plong2 = location.getLongitude();
  53.                 double plat2 = location.getLatitude();
  54.                
  55.             // maksudnya mau biar setiap location baru dia get coordinate trus langsung hitung gitu pak, ada ide gak? hehehe
  56.             //  Location locationA = new Location("point A");
  57.             //  locationA.setLatitude(plat);
  58.             //  locationA.setLongitude(plong);
  59.                
  60.             //  Location locationB = new Location("Point B");
  61.             //  locationB.setLongitude(plong2);
  62.             //  locationB.setLatitude(plat2);
  63.                
  64.             //  float distance = locationA.distanceTo(locationB);
  65.                
  66.             //  tampil.setText(Float.toString(distance));
  67.                 textLat.setText(Double.toString(plat));
  68.                 textLong.setText(Double.toString(plong));
  69.                
  70.             }
  71.         }
  72.  
  73.         @Override
  74.         public void onStatusChanged(String provider, int status, Bundle extras) {
  75.             // TODO Auto-generated method stub
  76.            
  77.         }
  78.  
  79.         @Override
  80.         public void onProviderEnabled(String provider) {
  81.             // TODO Auto-generated method stub
  82.  
  83.            
  84.         }
  85.  
  86.         @Override
  87.         public void onProviderDisabled(String provider) {
  88.             // TODO Auto-generated method stub
  89.            
  90.         }
  91.      }
  92.    
  93.     @Override
  94.     public boolean onCreateOptionsMenu(Menu menu) {
  95.         // Inflate the menu; this adds items to the action bar if it is present.
  96.         getMenuInflater().inflate(R.menu.main, menu);
  97.         return true;
  98.     }
  99.  
  100.     @Override
  101.     public boolean onOptionsItemSelected(MenuItem item) {
  102.         // Handle action bar item clicks here. The action bar will
  103.         // automatically handle clicks on the Home/Up button, so long
  104.         // as you specify a parent activity in AndroidManifest.xml.
  105.         int id = item.getItemId();
  106.         if (id == R.id.action_settings) {
  107.             return true;
  108.         }
  109.         return super.onOptionsItemSelected(item);
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement