android - MapView fix not compling -
i following error mapview: "cameraupdatefactory not initialized"
many posts out there suggest adding: mapsinitializer.initialize(this);
ide telling me: "googleplayservicesnotavailableexception never thrown"
my code below:
xml:
<com.google.android.gms.maps.mapview android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" />
and code run it:
mapview = (mapview) header.findviewbyid(r.id.mapview); map = mapview.getmap(); try { mapsinitializer.initialize(this); } catch (googleplayservicesnotavailableexception e) { e.printstacktrace(); } // updates location , zoom of mapview cameraupdate cameraupdate = cameraupdatefactory.newlatlngzoom(new latlng(43.1, -87.9), 10); map.animatecamera(cameraupdate);
first off, getting compiler warning because mapsinitializer.initialize(this);
not throw googleplayservicesnotavailableexception
. surrounding try/catch, introducing unreachable code in catch
.
now reason need call oncreate
, onresume
there lifecycle events logic google needs perform in order mapview
function properly. if using mapfragment
taken care of in background. ideally, put these method calls in respective activity/fragment methods. call mapview.oncreate()
in oncreate
method, mapview.onresume()
in onresume
, etc. should add calls onpause
, ondestroy
well.
hope clears things you. feel free follow questions this.
Comments
Post a Comment