Advertisement
phr3ncj

AndroidLocation.java

Jul 29th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.97 KB | None | 0 0
  1. package com.phtest.fun;
  2.  
  3. import com.google.android.maps.GeoPoint;
  4. import com.google.android.maps.MapActivity;
  5. import com.google.android.maps.MapController;
  6. import com.google.android.maps.MapView;
  7. import com.phtest.fun.R;
  8. import android.content.Context;
  9. import android.location.Location;
  10. import android.location.LocationListener;
  11. import android.location.LocationManager;
  12. import android.os.Bundle;
  13. import android.widget.TextView;
  14.  
  15. public class AndroidLocation extends MapActivity {
  16.  
  17.     private LocationManager myLocationManager;
  18.     private LocationListener myLocationListener;
  19.     private TextView myLongitude, myLatitude;
  20.  
  21.     private MapView myMapView;
  22.  
  23.     private MapController myMapController;
  24.  
  25.     private void CenterLocatio(GeoPoint centerGeoPoint) {
  26.         myMapController.animateTo(centerGeoPoint);
  27.  
  28.  
  29.         myLongitude.setText("Longitude: "+
  30.                 String.valueOf((float)centerGeoPoint.getLongitudeE6()/1000000)
  31.                 );
  32.         myLatitude.setText("Latitude: "+
  33.                 String.valueOf((float)centerGeoPoint.getLatitudeE6()/1000000)
  34.                 );
  35.     };
  36.  
  37.     /** Called when the activity is first created. */
  38.     @Override
  39.     public void onCreate(Bundle savedInstanceState) {
  40.         super.onCreate(savedInstanceState);
  41.         setContentView(R.layout.map);
  42.         myMapView = (MapView)findViewById(R.id.mapview);
  43.         myLongitude = (TextView)findViewById(R.id.longitude);
  44.         myLatitude = (TextView)findViewById(R.id.latitude);
  45.         myMapView.setSatellite(true); //Set satellite view
  46.         myMapController = myMapView.getController();
  47.         myMapController.setZoom(20); //Fixed Zoom Level
  48.  
  49.         myLocationManager = (LocationManager)getSystemService(
  50.                 Context.LOCATION_SERVICE);
  51.  
  52.         myLocationListener = new MyLocationListener();
  53.  
  54.         myLocationManager.requestLocationUpdates(
  55.                 LocationManager.GPS_PROVIDER,
  56.                 0,
  57.                 0,
  58.                 myLocationListener);
  59.  
  60.         //Get the current location in start-up
  61.         /*GeoPoint initGeoPoint = new GeoPoint(
  62.                 (int)(myLocationManager.getLastKnownLocation(
  63.                         LocationManager.GPS_PROVIDER)
  64.                         .getLatitude()*1000000),
  65.                         (int)(myLocationManager.getLastKnownLocation(
  66.                                 LocationManager.GPS_PROVIDER)
  67.                                 .getLongitude()*1000000));*/
  68.         GeoPoint gp = new GeoPoint(0, 0);
  69. //      CenterLocatio(gp);
  70.         myMapController.setCenter(gp);
  71.     }
  72.  
  73.     private class MyLocationListener implements LocationListener{
  74.  
  75.         public void onLocationChanged(Location argLocation) {
  76.             // TODO Auto-generated method stub
  77.             GeoPoint myGeoPoint = new GeoPoint(
  78.                     (int)(argLocation.getLatitude()*1000000),
  79.                     (int)(argLocation.getLongitude()*1000000));
  80.  
  81.             CenterLocatio(myGeoPoint);
  82.         }
  83.  
  84.         public void onProviderDisabled(String provider) {
  85.             // TODO Auto-generated method stub
  86.         }
  87.  
  88.         public void onProviderEnabled(String provider) {
  89.             // TODO Auto-generated method stub
  90.         }
  91.  
  92.         public void onStatusChanged(String provider,
  93.                 int status, Bundle extras) {
  94.             // TODO Auto-generated method stub
  95.         }
  96.     }
  97.  
  98.     @Override
  99.     protected boolean isRouteDisplayed() {
  100.         // TODO Auto-generated method stub
  101.         return false;
  102.     };
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement