当用户点击地图时,我试图放置一个标记。我正在使用SupportMapFragment
内部一个ActionBarActivity
. 但是地图没有响应,此外,map.setMapType()
操作不起作用。
这是我的代码:
private GoogleMap map;
private Marker marker;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ActionBarActivity activity = (ActionBarActivity) getActivity();
activity.getSupportActionBar().setTitle(R.string.select_location);
super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.map, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Log.d("Map","On view created");
map = getMap();
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
map.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
Log.d("Map","Map clicked");
marker.remove();
drawMarker(point);
}
});
...
Location location = locationManager.getLastKnownLocation(provider);
if(location!=null){
//PLACE THE INITIAL MARKER
drawMarker(new LatLng(location.getLatitude(),location.getLongitude()));
}
}
Logcat 显示“on view created”消息,并且地图显示当前位置并带有标记,因此代码的最后一部分正在执行。但是onMapClickListener
由于它不起作用,并且地图不是卫星,所以它被覆盖了。
有谁能够帮我?