Guest User

Untitled

a guest
Jan 21st, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. public class BreakDownOnMaps extends FragmentActivity implements
  2.         OnMapReadyCallback {
  3.     double currentLatitude;
  4.     double currentLongitude;
  5.     LatLng latLng;
  6.     GoogleMap gMap;
  7.     private MyLocationListener myLocationListener;
  8.  
  9.     @TargetApi(Build.VERSION_CODES.M)
  10.     @Override
  11.     protected void onCreate(Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.activity_break_down_on_maps);
  14.         SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
  15.                 .findFragmentById(R.id.map);
  16.         mapFragment.getMapAsync(this);
  17.         myLocationListener = new MyLocationListener(this);
  18.     }
  19.  
  20.     @Override
  21.     protected void onStart() {
  22.         super.onStart();
  23.         myLocationListener.connect();
  24.     }
  25.  
  26.     @Override
  27.     protected void onResume() {
  28.         super.onResume();
  29.         myLocationListener.connect();
  30.     }
  31.  
  32.     public void handleNewLocation(Location loc) {
  33.         currentLatitude = loc.getLatitude();
  34.         currentLongitude = loc.getLongitude();
  35.         latLng = new LatLng(currentLatitude, currentLongitude);
  36.         System.out.println("handleNewLocation ");
  37.         MarkerOptions options = new MarkerOptions()
  38.                 .position(latLng)
  39.                 .title("I am here!");
  40.         gMap.addMarker(options);
  41.         gMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
  42.     }
  43.  
  44.     @Override
  45.     public void onMapReady(GoogleMap googleMap) {
  46.         System.out.println("currentLatitude : " + currentLatitude);
  47.         System.out.println("currentLongitude : " + currentLongitude);
  48.         latLng = new LatLng(currentLatitude, currentLongitude);
  49.         setgMap(googleMap);
  50.         if(currentLatitude != 0 || currentLongitude != 0) {
  51.             MarkerOptions options = new MarkerOptions()
  52.                     .position(latLng)
  53.                     .title("I am here!");
  54.             googleMap.addMarker(options);
  55.             googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
  56.         }
  57.     }
  58.  
  59.     public void setgMap(GoogleMap gMap) {
  60.         this.gMap = gMap;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment