android - How to add the marker on the map after camera animation has finished -
i trying draw marker showing user's current location although have enabled setmycurrentlocation in map while initializing it, getting the latitude , longitude of current location . doing showing marker @ current location . how doing
googlemap.animatecamera(cameraupdatefactory.zoomto(15), 8000, new googlemap.cancelablecallback() { @override public void onfinish() { handler handler1 = new handler(); handler1.postdelayed(new runnable() { public void run() { addmarker(googlemap.getlocation.getlatitude(), googlemap.getlocation.getlatitude());
and addmarker function goes
private void addmarker(double lat, double long) { /** make sure map has been initialised **/ if (null != googlemap) { googlemap.addmarker(new markeroptions() .position(new latlng(lat, long)) .title("you") .draggable(true) ); } }
so peace of code of adding marker works if try using out side of onfinished function of map animation ,
some times gives me null unable location map. tried put after when camera stop animation.
but in case not working , idea ? or else other way can add marker when camera stop animation .?
as comments , code, seems want have multiple markers of user location on map, code using obtaining user location not ok (i can't find googlemap.getlocation , maybe code not complete). method getmylocation() of google maps deprecated: https://developers.google.com/android/reference/com/google/android/gms/maps/googlemap.html#getmylocation()
this method deprecated.
use com.google.android.gms.location.fusedlocationproviderapi instead. fusedlocationproviderapi provides improved location finding , power usage , used "my location" blue dot. see mylocationdemoactivity in sample applications folder example example code, or location developer guide.
the link points https://developers.google.com/maps/documentation/android/location
which ports tu use fusedlocationprovider. have @ guides obtain user location. when have done it, can put code in onfinish callback.
if need fused location provider maybe should check existent questions or open new 1 appropriate tags!
Comments
Post a Comment