1
I am studying the google maps api and was using it as a basis for my video studies available on youtube. However, while I was studying I came across a code depreciation problem. The video class that was 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 that I have to make it work properly. The function in question is the "getMap()" of the API that I tried to replace 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, which changes I need to make to the code work without error?
Thank you for responding!
– CloudAC