google maps - Android - Tracking using GPS, getMap depricated -
this question has answer here:
- replace getmap getmapasync 3 answers
public class locationactivity extends fragmentactivity implements locationlistener, googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener { private static final string tag = "locationactivity"; private static final long interval = 1000 * 60 * 1; //1 minute private static final long fastest_interval = 1000 * 60 * 1; // 1 minute button btnfusedlocation; textview tvlocation; locationrequest mlocationrequest; googleapiclient mgoogleapiclient; location mcurrentlocation; string mlastupdatetime; googlemap googlemap; protected void createlocationrequest() { mlocationrequest = new locationrequest(); mlocationrequest.setinterval(interval); mlocationrequest.setfastestinterval(fastest_interval); mlocationrequest.setpriority(locationrequest.priority_high_accuracy); } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (!isgoogleplayservicesavailable()) { finish(); } createlocationrequest(); mgoogleapiclient = new googleapiclient.builder(this) .addapi(locationservices.api) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .build(); setcontentview(r.layout.activity_location_google_map); supportmapfragment fm = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.map); googlemap = fm.getmap(); googlemap.getuisettings().setzoomcontrolsenabled(true); } }
i'm trying track using gps , plot location on map. tried above code getmap depricated , i'm getting screen on phone. me how solve issue? in advance :)
getmap() deprecated.you need implement onmapreadycallback
in class
public class locationactivity extends fragmentactivity implements locationlistener, googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener, onmapreadycallback {
and override the: onmapready()
function
@override public void onmapready(googlemap map) { googlemap = map; googlemap.getuisettings().setzoomcontrolsenabled(true); //add code here }
also in code add:
supportmapfragment fm = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.map); fm.getmapasync(this);
and in layout:
<fragment android:id="@+id/map" android:name="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="match_parent">
Comments
Post a Comment