In my project I'm loading my maps programmatically on a fragment. However, adding markers on this map is not working. No error is shown but the marker is not on the map as well.
I'm following the specification so i have no idea why it is not working. (Lat and Lng of the marker and the camera are the same)
My Fragment Code
public class MainMapFragment extends Fragment implements OnMapReadyCallback {
SupportMapFragment mMapFragment;
static final LatLng LIBRARY = new LatLng(Lat, Lng);
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
return inflater.inflate(R.layout.main_map_layout,container,false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
//Set the initial stage of the map
//It is set on code (not on the xml) because the map is created programmatically
GoogleMapOptions options = new GoogleMapOptions();
CameraPosition ufv_position = new CameraPosition.Builder()
.target(new LatLng(Lat,Lng))
.zoom(15)
.tilt(0)
.bearing(40)
.build();
options.mapType(GoogleMap.MAP_TYPE_NORMAL)
.compassEnabled(false)
.rotateGesturesEnabled(false)
.tiltGesturesEnabled(false)
.camera(ufv_position);
//Load the map with the given options
mMapFragment = SupportMapFragment.newInstance(options);
FragmentTransaction fragmentTransaction =
getChildFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.map, mMapFragment);
fragmentTransaction.commit();
}
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.addMarker(new MarkerOptions()
.position(LIBRARY)
.title("Library")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.book)));
}
}
add mMapFragment.getMapAsync(this);
so your onMapReady method gets called
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.