Java Code Examples for com.google.android.gms.maps.SupportMapFragment#getMapAsync()

The following examples show how to use com.google.android.gms.maps.SupportMapFragment#getMapAsync() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapFragment.java    From droidkaigi2016 with Apache License 2.0 6 votes vote down vote up
@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
void initGoogleMap() {
    SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);

    mapFragment.getMapAsync(googleMap -> {
        //noinspection MissingPermission
        googleMap.setMyLocationEnabled(true);
        binding.mapSearchView.bindData(placeMapList, placeMap -> {
            LatLng latLng = new LatLng(placeMap.latitude, placeMap.longitude);
            int duration = getResources().getInteger(R.integer.map_camera_move_mills);
            googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng), duration, null);
            Marker marker = markers.get(placeMap.nameRes);
            if (marker != null) marker.showInfoWindow();
        });

        binding.loadingView.setVisibility(View.GONE);
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        googleMap.setIndoorEnabled(true);
        googleMap.setBuildingsEnabled(true);
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LAT_LNG_CENTER, DEFAULT_ZOOM));
        UiSettings mapUiSettings = googleMap.getUiSettings();
        mapUiSettings.setCompassEnabled(true);
        renderMarkers(placeMapList, googleMap);
    });
}
 
Example 2
Source File: NearByHospitalActivity.java    From BloodBank with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(getActivity());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        checkLocationPermission();
    }

    SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.gMap);
    if (mapFragment != null) {
        mapFragment.getMapAsync(this);
    }
    else
    {
        Toast.makeText(getActivity(), "MapFragment is null, why?", Toast.LENGTH_LONG).show();
    }

}
 
Example 3
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getSupportActionBar().hide();  // for hiding
    prefs = getSharedPreferences("MIB", Context.MODE_PRIVATE);
    editor = prefs.edit();

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        bPermissionGranted = checkLocationPermission();
    }


    mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFrag.getMapAsync(this);
    setUpMapIfNeeded();
}
 
Example 4
Source File: MapsActivity.java    From journaldev with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    button = findViewById(R.id.btnChangeStyle);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            setMapStyle();
        }
    });


    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
 
Example 5
Source File: MapsActivity.java    From Krishi-Seva with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    String lat= getIntent().getStringExtra("lat");
    String longg= getIntent().getStringExtra("long");
    latitude= Double.parseDouble(lat);
    longitude= Double.parseDouble(longg);
    kochi = new LatLng(latitude, longitude);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        checkLocationPermission();
    }

    if (!CheckGooglePlayServices()) {
        Log.d("onCreate", "Finishing test case since Google Play Services are not available");
        finish();
    }
    else {
        Log.d("onCreate","Google Play Services available.");
    }

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
 
Example 6
Source File: TrackLocationActivity.java    From Track-My-Location with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_track_location);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    ButterKnife.bind(this);
    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.track_location);
    }

    ((App) getApplication()).getAppComponent().inject(this);
    initViewModel();
}
 
Example 7
Source File: CameraClampingDemoActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.camera_clamping_demo);

    mMap = null;
    resetMinMaxZoom();

    mCameraTextView = (TextView) findViewById(R.id.camera_text);

    SupportMapFragment mapFragment =
        (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
 
Example 8
Source File: LocationSourceActivity.java    From Complete-Google-Map-API-Tutorial with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_location_source);

	SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
	mapFragment.getMapAsync(this);
}
 
Example 9
Source File: MapsActivity.java    From Compass with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
 
Example 10
Source File: RetainMapDemoActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.basic_demo);

    SupportMapFragment mapFragment =
            (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

    if (savedInstanceState == null) {
        // First incarnation of this activity.
        mapFragment.setRetainInstance(true);
    }

    mapFragment.getMapAsync(this);
}
 
Example 11
Source File: MapsActivity.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
 
Example 12
Source File: ShapeActivity.java    From Complete-Google-Map-API-Tutorial with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_shape);

	SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
	mapFragment.getMapAsync(this);

	initialize();
}
 
Example 13
Source File: MapsActivity.java    From AndroidBlueprints with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
 
Example 14
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);//Indicamos el contexto de la actividad actual
}
 
Example 15
Source File: DriverTracking.java    From UberClone with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_driver_tracking);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    if(getIntent()!=null){
        riderLat=getIntent().getDoubleExtra("lat",-1.0);
        riderLng=getIntent().getDoubleExtra("lng",-1.0);
        riderID = getIntent().getStringExtra("riderID");
        riderToken=getIntent().getStringExtra("token");
    }
    database = FirebaseDatabase.getInstance();
    historyDriver = database.getReference(Common.history_driver).child(Common.userID);
    historyRider = database.getReference(Common.history_rider).child(riderID);
    riderInformation=database.getReference(Common.user_rider_tbl);
    tokens=database.getReference(Common.token_tbl);
    drivers= FirebaseDatabase.getInstance().getReference(Common.driver_tbl).child(Common.currentUser.getCarType());
    geoFire=new GeoFire(drivers);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    verifyGoogleAccount();


    mService = Common.getGoogleAPI();
    mFCMService=Common.getFCMService();
    location=new Location(this, new locationListener() {
        @Override
        public void locationResponse(LocationResult response) {
            // refresh current location
            Common.currentLat=response.getLastLocation().getLatitude();
            Common.currentLng=response.getLastLocation().getLongitude();
            displayLocation();

        }
    });
    btnStartTrip=(Button)findViewById(R.id.btnStartTrip);
    btnStartTrip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(btnStartTrip.getText().equals("START TRIP")){
                pickupLocation=new LatLng(Common.currentLat, Common.currentLng);
                btnStartTrip.setText("DROP OFF HERE");
            }else if(btnStartTrip.getText().equals("DROP OFF HERE")){
                calculateCashFree(pickupLocation, new LatLng(Common.currentLat, Common.currentLng));
            }
        }
    });
    getRiderData();
}
 
Example 16
Source File: MapsActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_maps);

  // Obtain the SupportMapFragment and request the Google Map object.
  SupportMapFragment mapFragment =
    (SupportMapFragment)getSupportFragmentManager()
                          .findFragmentById(R.id.map);
  mapFragment.getMapAsync(this);
}
 
Example 17
Source File: EarthquakeMapFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view,
                          Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);

  // Obtain the SupportMapFragment and request the Google Map object.
  SupportMapFragment mapFragment
    = (SupportMapFragment)getChildFragmentManager()
                            .findFragmentById(R.id.map);

  mapFragment.getMapAsync(this);
}
 
Example 18
Source File: FragMap.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.compass_map, container, false);

    SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    mFab = v.findViewById(R.id.myLocationButton);

    if (!PermissionUtils.get(getActivity()).pLocation) {
        PermissionUtils.get(getActivity()).needLocation(getActivity());
    }
    return v;
}
 
Example 19
Source File: MapDialogFragment.java    From openshop.io-android with MIT License 4 votes vote down vote up
public MapDialogFragment() {
    super();
    supportMapFragment = new SupportMapFragment();
    supportMapFragment.getMapAsync(this);
}
 
Example 20
Source File: SearchClinics.java    From Crimson with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_clinics);


    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    getLocation();

}