android - How to know if Google maps is ready to be used? -


i have simple activity follow segment code on :

<?xml version="1.0" encoding="utf-8"?> <linearlayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:gravity="center_horizontal"     android:orientation="horizontal"     android:id="@+id/title_complex">     <fragment        android:id="@+id/map"       android:layout_width="match_parent"       android:layout_height="match_parent"       class="com.google.android.gms.maps.mapfragment"         tools:context=".mainactivity" />  </linearlayout> 
  • how check in mainactivity.java if map loaded , ready ?

before can interact googlemap object, need confirm object can instantiated, , google play services components correctly installed on target device. can verify googlemap available calling

mapfragment.getmap()

or

mapview.getmap()

methods , checking returned object not null.

an example of test confirm availability of googlemap shown below. method can called both oncreate() , onresume() stages ensure map available.

private void setupmapifneeded() { // null check confirm have not instantiated map. if (mmap == null) {     mmap = ((mapfragment) getfragmentmanager().findfragmentbyid(r.id.map))                         .getmap();     // check if successful in obtaining map.     if (mmap != null) {         // map verified. safe manipulate map.      } } } 

references - https://developers.google.com/maps/documentation/android/map


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -