为什么错误CameraUpdateFactory未在MapsFragment android中初始化?

时间:2015-10-05 01:03:01

标签: java android eclipse google-maps google-maps-android-api-2

我想在地图中显示一些点,但是当我在地图上设置相机时,为什么会出现此错误?如果订单CameraUpdateFactory程序出错,以前我没有遇到错误

public class Maps<Passing> extends FragmentActivity implements LocationListener { private GoogleMap map; private DBAdapter dbhelper; private SQLiteDatabase db = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dbhelper = new DBAdapter(this); db = dbhelper.getWritableDatabase(); dbhelper.delAllData(db); //dbhelper.delAllData2(db); dbhelper.generateDataLokasi(db); dbhelper.generateDataRS(db); setContentView(R.layout.maps); SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); map = fm.getMap(); map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-6.604345, 106.796640), 12)); map.setMyLocationEnabled(true); Cursor c = dbhelper.fetchAllLokasi(db); int col = dbhelper.fetchAllLokasi(db).getCount(); if (col == 0) { Toast.makeText(Maps.this, "Pas de donnees ", Toast.LENGTH_LONG) .show(); } else { c.moveToFirst(); while (c.isAfterLast() == false) { String id = "" + c.getInt(0); String nama = c.getString(1); String longitude = c.getString(3); String latitude = c.getString(2); String ket = c.getString(4); Marker marker = map.addMarker(new MarkerOptions() .position( new LatLng(Double.parseDouble(latitude), Double .parseDouble(longitude))) .title(nama) .snippet(ket) .icon(BitmapDescriptorFactory .fromResource(R.drawable.icmarker))); c.moveToNext(); } }

Full是CameraUpdateFactory的草案代码,这有什么问题吗?

Maps.java

c >= 1/(2^(n-2))

我没有找到这个答案,有几次我运行这个应用程序,修复错误,如果我的代码有问题?请帮忙

1 个答案:

答案 0 :(得分:1)

我认为您需要明确调用MapsInitializer

示例代码:

@Override public View 
onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.map_panel, container, false);
    mapView = (MapView) view.findViewById(R.id.map_view);
    mapView.onCreate(savedInstanceState);
    configureMap(mapView.getMap());
    return view;
}

private void 
configureMap(GoogleMap map, double lat, double lon)
{
    if (map == null)
        return; // Google Maps not available
    try {
        MapsInitializer.initialize(getActivity());
    }
    catch (GooglePlayServicesNotAvailableException e) {
        Log.e(LOG_TAG, "Have GoogleMap but then error", e);
        return;
    }
    map.setMyLocationEnabled(true);
    LatLng latLng = new LatLng(lat, lon);
    CameraUpdate camera = CameraUpdateFactory.newLatLng(latLng);
    map.animateCamera(camera);
}