android - Get Current Location on Google Map not working properly? -


i take current location put marker on map working time not working don't know why me find out fault in code. code take current location , put marker on map.

this java file mapactivity.java

try {         if (googlemap == null) {             googlemap = ((mapfragment) getactivity().getfragmentmanager()                     .findfragmentbyid(r.id.map)).getmap();             googlemap.getuisettings().setzoomcontrolsenabled(false);         }         googlemapoptions options = new googlemapoptions();         options.maptype(googlemap.map_type_normal).compassenabled(false)                 .rotategesturesenabled(false).tiltgesturesenabled(false);          // current location         locationmanager locationmanager = (locationmanager) getactivity()                 .getsystemservice(context.location_service);         criteria criteria = new criteria();         location location = locationmanager                 .getlastknownlocation(locationmanager.getbestprovider(                         criteria, true));          if (location != null) {             currentlatlng = (new latlng(location.getlatitude(),                     location.getlongitude()));              googlemap.animatecamera(cameraupdatefactory.newlatlngzoom(                     new latlng(location.getlatitude(), location                             .getlongitude()), 13));              marker marker = googlemap.addmarker(new markeroptions()                     .position(currentlatlng));              cameraposition cameraposition = new cameraposition.builder()                     .target(currentlatlng).zoom(12)                     .bearing(90).tilt(40).build();              googlemap.animatecamera(cameraupdatefactory                     .newcameraposition(cameraposition));              circleoptions circleoptions = new circleoptions()                     .center(currentlatlng).radius(200)                     .fillcolor(color.transparent)                     .strokecolor(0x10000000).strokewidth(5);              mcircle = googlemap.addcircle(circleoptions);         }      } catch (exception e) {         e.printstacktrace();     } 

after calling animatecamera() ,you need call setmylocationenabled(true) e.g

    googlemap.animatecamera(cameraupdatefactory.newlatlngzoom(                     new latlng(location.getlatitude(), location                             .getlongitude()), 13));     googlemap.setmylocationenabled(true); 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -