【发布时间】:2016-04-06 13:35:54
【问题描述】:
在我的项目中,我以编程方式将地图加载到片段上。但是,在此地图上添加标记不起作用。没有显示错误,但标记也不在地图上。
我正在关注specification,所以我不知道它为什么不起作用。 (marker和相机的Lat和Lng是一样的)
我的片段代码
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)));
}
}
【问题讨论】:
-
我只是隐藏了问题的坐标。但我把它放在我设置相机的同一个地方。 (这是一个有效的坐标)
标签: android google-maps