MapScreen.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.example.yiupang.freefoodfinder;
  2. import android.os.Bundle;
  3. import android.support.annotation.Nullable;
  4. import android.view.LayoutInflater;
  5. import android.view.View;
  6. import android.view.ViewGroup;
  7. import com.google.android.gms.maps.CameraUpdateFactory;
  8. import com.google.android.gms.maps.GoogleMap;
  9. import com.google.android.gms.maps.OnMapReadyCallback;
  10. import com.google.android.gms.maps.SupportMapFragment;
  11. import com.google.android.gms.maps.model.BitmapDescriptorFactory;
  12. import com.google.android.gms.maps.model.LatLng;
  13. import com.google.android.gms.maps.model.MarkerOptions;
  14. /**
  15. * Created by yiupang on 5/6/2017.
  16. *
  17. *
  18. */
  19. public class MapScreen extends android.support.v4.app.Fragment implements OnMapReadyCallback
  20. {
  21. @Override
  22. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
  23. {
  24. View view = inflater.inflate(R.layout.map_screen, container, false);
  25. android.support.v4.app.FragmentManager fragmentManager = getChildFragmentManager();
  26. SupportMapFragment mapFragment = (SupportMapFragment) fragmentManager.findFragmentById(R.id.map);
  27. mapFragment.getMapAsync(this);
  28. return view;
  29. }
  30. //CODE SMELL: remove comment block
  31. /* @Override
  32. public void onCreate(Bundle savedInstanceState)
  33. {
  34. super.onCreate(savedInstanceState);
  35. setContentView(R.layout.map_screen);
  36. }*/
  37. @Override
  38. public void onMapReady(GoogleMap map)
  39. {
  40. // Add a marker in Sydney and move the camera
  41. LatLng slo = new LatLng(35.2827778, -120.6586111);
  42. LatLng sf = new LatLng(37.774929, -122.419416);
  43. LatLng theP = new LatLng(35.302833, -120.651662);
  44. map.addMarker(new MarkerOptions().position(slo).title("Downtown").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)).snippet("Downtown of slo"));
  45. map.addMarker(new MarkerOptions().position(theP).title("The P").snippet("The “P” is a 50-by-30 foot landmark located atop a northwestern hill of California Polytechnic State University, San Luis Obispo, California."));
  46. map.addMarker(new MarkerOptions().position(sf).title("Marker in sf").snippet("Golden Gate Bridge"));
  47. map.moveCamera(CameraUpdateFactory.newLatLngZoom(slo, 12.0f));
  48. }
  49. }