I'm studying google maps api and was using as a basis for my studies video-lessons made available on youtube. However, while I was studying I came across a code depreciation problem. The video lesson you were following is using a function that no longer exists in the current version of android. I would like you to help me adapt the code I have for it to work correctly. The function in question is the "getMap ()" of the API that I tried to override for getMapAsync () (which, according to the documentation, is the equivalent function), but which also continued with error. The original code in question is this:
public class MainActivity extends FragmentActivity{
private GoogleMap map;
private SupportMapFragment mapFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMapOptions options = new GoogleMapOptions();
options.zOrderOnTop(true);
mapFragment = SupportMapFragment.newInstance(options);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.llContainer, mapFragment);
ft.commit();
}
public void onResume(){
super.onResume();
new Thread(){
public void run(){
while(mapFragment.getMap() == null){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
configMap();
}
});
}
}.start();
}
public void configMap(){
map = mapFragment.getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LatLng latLng = new LatLng(-23, -46);
CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(18).build();
CameraUpdate update = CameraUpdateFactory.newCameraPosition(cameraPosition);
map.animateCamera(update, 3000, new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
Log.i("Script", "CancelableCallback.OnFinish");
}
@Override
public void onCancel() {
Log.i("Script", "CancelableCallback.OnCancel");
}
});
}
Can anyone help me with this problem, what changes do I need to make to code work without error?