I have added a map fragment to my application and added the following code to place a marker on the fragment.But I'm getting errors in the code snippet.I have included all relevant imports.
The errors are compile time and are as follows:
1.MapFragment cannot be resolved to a type.
2.GoogleMap cannot be resolved to a type.
3.LatLng cannot be resolved to a type.
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Hello world"));
Anyone have any ideas where the error is in the snippet? Thanks
I think you should check two things first
If you compile for android version < 11, you need to use supportFragmentManager instead of the normal FragmentManager :
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
In the last case, you also need to update the class used in your XML to class="com.google.android.gms.maps.SupportMapFragment"