java - Android Google Maps Zoom not to right Location and Activity Crash when high frequently open and close -


i've got problem mapmapfragment of googlemaps in android.

i used method, have override:

@override public void onmapready(googlemap googlemap) {      gm = googlemap;     gm.setmaptype(googlemap.map_type_hybrid);     if (activitycompat.checkselfpermission(this, android.manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(this, android.manifest.permission.access_coarse_location) != packagemanager.permission_granted) {         toast.maketext(getapplicationcontext(), getapplicationcontext().getresources().getstring(r.string.choose_festival_gps_disabled), toast.length_short).show();     } else {         gm.setmylocationenabled(true);     }     gm.getuisettings().setzoomcontrolsenabled(true);     gm.addmarker(new markeroptions().position(new latlng(latitude(), longitude())).title(name()));     gm.movecamera(cameraupdatefactory.newlatlng(new latlng(latitude(), longitude())));     gm.animatecamera(cameraupdatefactory.zoomto(15));  } 

then called 1 in async task:

((mapfragment) getfragmentmanager().findfragmentbyid(r.id.map)).getmapasync(activity.this); 

now got 2 problems, i've searched long time got no clue how solve it:

  1. the map zoom not location, maybe 5 km northern of it.
  2. if open , close activity high frequently, i've got following fatal exception.

    java.lang.nullpointerexception: attempt invoke virtual method 'void com.google.android.gms.maps.mapfragment.getmapasync(com.google.android.gms.maps.onmapreadycallback)' on null object reference

1. map zoom not location, maybe 5 km northern of it.

you can check on so thread. advised add locationsource googlemap , respond onlocationchanged events. can check sample code here.

2. if open , close activity high frequently, i've got following fatal exception.

maybe attempting find fragment before exists. or maybe you're trying @ map fragment inside fragment in fragment's oncreateview() method. stated in so post. can see here might encounter error if using specific version of google play services gradle build select recent version.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -