9
9
import com .example .instabug .R ;
10
10
import com .example .instabug .ui .views .CustomGoogleMap ;
11
11
import com .google .android .gms .maps .GoogleMap ;
12
+ import com .google .android .gms .maps .OnMapReadyCallback ;
12
13
import com .google .android .gms .maps .SupportMapFragment ;
13
14
import com .google .android .gms .maps .model .LatLng ;
14
15
import com .google .android .gms .maps .model .MarkerOptions ;
15
16
import com .instabug .library .Instabug ;
16
17
17
- public class GoogleMapsActivity extends AppCompatActivity {
18
+ public class GoogleMapsActivity extends AppCompatActivity implements OnMapReadyCallback {
18
19
19
20
private GoogleMap mMap ; // Might be null if Google Play services APK is not available.
20
- private CustomGoogleMap customGoogleMap ;
21
+ private SupportMapFragment mapFragment ;
21
22
22
23
@ Override
23
24
protected void onCreate (Bundle savedInstanceState ) {
@@ -30,45 +31,10 @@ public void onClick(View v) {
30
31
Toast .makeText (GoogleMapsActivity .this , "File saved to be uploaded" , Toast .LENGTH_SHORT ).show ();
31
32
}
32
33
});
33
- setUpMapIfNeeded ();
34
- }
35
-
36
- @ Override
37
- protected void onResume () {
38
- super .onResume ();
39
- setUpMapIfNeeded ();
40
- }
41
-
42
- /**
43
- * Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly
44
- * installed) and the map has not already been instantiated.. This will ensure that we only ever
45
- * call {@link #setUpMap()} once when {@link #mMap} is not null.
46
- * <p/>
47
- * If it isn't installed {@link com.google.android.gms.maps.SupportMapFragment} (and
48
- * {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to
49
- * install/update the Google Play services APK on their device.
50
- * <p/>
51
- * A user can return to this FragmentActivity after following the prompt and correctly
52
- * installing/updating/enabling the Google Play services. Since the FragmentActivity may not
53
- * have been completely destroyed during this process (it is likely that it would only be
54
- * stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this
55
- * method in {@link #onResume()} to guarantee that it will be called.
56
- */
57
- private void setUpMapIfNeeded () {
58
- // Do a null check to confirm that we have not already instantiated the map.
59
- if (mMap == null ) {
60
- // Try to obtain the map from the SupportMapFragment.
61
- mMap = ((SupportMapFragment ) getSupportFragmentManager ().findFragmentById (R .id .map ))
62
- .getMap ();
63
- customGoogleMap = new CustomGoogleMap (getSupportFragmentManager ().findFragmentById (R .id .map ).getView (), mMap );
64
- // TODO add this so that instabug recognizes you have a map and show it in the screenshot
65
- Instabug .addCapturableView (customGoogleMap );
66
34
67
- // Check if we were successful in obtaining the map.
68
- if (mMap != null ) {
69
- setUpMap ();
70
- }
71
- }
35
+ mapFragment =
36
+ (SupportMapFragment ) getSupportFragmentManager ().findFragmentById (R .id .map );
37
+ mapFragment .getMapAsync (this );
72
38
}
73
39
74
40
/**
@@ -80,4 +46,14 @@ private void setUpMapIfNeeded() {
80
46
private void setUpMap () {
81
47
mMap .addMarker (new MarkerOptions ().position (new LatLng (0 , 0 )).title ("Marker" ));
82
48
}
49
+
50
+ @ Override
51
+ public void onMapReady (GoogleMap googleMap ) {
52
+ mMap = googleMap ;
53
+ CustomGoogleMap customGoogleMap = new CustomGoogleMap (mapFragment .getView (), mMap );
54
+ // TODO add this so that instabug recognizes you have a map and show it in the screenshot
55
+ Instabug .addCapturableView (customGoogleMap );
56
+
57
+ setUpMap ();
58
+ }
83
59
}
0 commit comments