chore: Adding regiontag for MapsMarkerActivity (#195)

This commit is contained in:
Chris Arriola 2020-05-08 08:45:09 -07:00 committed by GitHub
parent 69f17a8fb0
commit 5ac76bb18b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 18 deletions

View File

@ -27,9 +27,12 @@ import com.google.android.gms.maps.model.MarkerOptions;
/**
* An activity that displays a Google map with a marker (pin) to indicate a particular location.
*/
// [START maps_marker_on_map_ready]
public class MapsMarkerActivity extends AppCompatActivity
implements OnMapReadyCallback {
// [START_EXCLUDE]
// [START maps_marker_get_map_async]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -41,7 +44,10 @@ public class MapsMarkerActivity extends AppCompatActivity
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
// [END maps_marker_get_map_async]
// [END_EXCLUDE]
// [START_EXCLUDE silent]
/**
* Manipulates the map when it's available.
* The API invokes this callback when the map is ready to be used.
@ -51,6 +57,7 @@ public class MapsMarkerActivity extends AppCompatActivity
* Play services inside the SupportMapFragment. The API invokes this method after the user has
* installed Google Play services and returned to the app.
*/
// [END_EXCLUDE silent]
@Override
public void onMapReady(GoogleMap googleMap) {
// Add a marker in Sydney, Australia,
@ -61,3 +68,4 @@ public class MapsMarkerActivity extends AppCompatActivity
googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
// [END maps_marker_on_map_ready]

View File

@ -19,8 +19,11 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.coroutineScope
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
import com.google.maps.android.ktx.MapsExperimentalFeature
import com.google.maps.android.ktx.addMarker
import com.google.maps.android.ktx.awaitMap
@ -28,9 +31,11 @@ import com.google.maps.android.ktx.awaitMap
/**
* An activity that displays a Google map with a marker (pin) to indicate a particular location.
*/
class MapsMarkerActivity : AppCompatActivity() {
// [START maps_marker_on_map_ready]
class MapsMarkerActivity : AppCompatActivity(), OnMapReadyCallback {
@MapsExperimentalFeature
// [START_EXCLUDE]
// [START maps_marker_get_map_async]
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Retrieve the content view that renders the map.
@ -41,23 +46,21 @@ class MapsMarkerActivity : AppCompatActivity() {
// Get the SupportMapFragment and request notification when the map is ready to be used.
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment
mapFragment?.getMapAsync(this)
}
// [END maps_marker_get_map_async]
// [END_EXCLUDE]
// This is using Android's Lifecycle-aware architecture components to launch and run the
// provided code block so that it executes as soon as the Activity is at least in the
// CREATED state.
lifecycle.coroutineScope.launchWhenCreated {
val googleMap = mapFragment?.awaitMap()
// Execution pauses here until we get the callback from the Maps SDK with a googleMap.
// This is where we can add markers or lines, add listeners or move the camera.
// In this case, we just move the camera to Sydney and add a marker in Sydney.
googleMap?.apply {
val sydney = LatLng(-33.852, 151.211)
addMarker {
position(sydney)
title("Marker in Sydney")
}
moveCamera(CameraUpdateFactory.newLatLng(sydney))
}
override fun onMapReady(googleMap: GoogleMap?) {
googleMap?.apply {
val sydney = LatLng(-33.852, 151.211)
addMarker(
MarkerOptions()
.position(sydney)
.title("Marker in Sydney")
)
moveCamera(CameraUpdateFactory.newLatLng(sydney))
}
}
}
// [END maps_marker_on_map_ready]