如何将此代码从谷歌android v1转换为v2?

时间:2013-12-20 03:35:48

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

我想将此示例v1 google地图转换为v2。 我试过像教程一样转换,但我失败了,你能帮助我吗?

我的活动代码是这样的:

package com.mtower.adha.ui;

import greendroid.widget.ActionBar;
import greendroid.widget.ActionBar.Type;

import java.util.List;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.mtower.adha.R;
import com.mtower.adha.db.TowerController;
import com.mtower.adha.models.TowerModel;
import com.mtower.adha.utilities.MapOverlay;


public class Map extends MapActivity {

    private MapView mapView;
    private ActionBar actionBar;
    private MapController mapController;
    private GeoPoint gpUser, p;
    private SharedPreferences prefLocation;

    private Context mContext;
    String lat, lon, name, alamat;
    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.map);
        mContext = this;

        actionBar = (ActionBar) findViewById(R.id.myActionBar);
        actionBar.setTitle("Cellular Tower Maps");
        actionBar.setType(Type.Empty);
        actionBar.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });
        actionBar.getHandler();


        initMap();
    }

    @SuppressWarnings("deprecation")
    public void initMap() {
        mapView = (MapView) findViewById(R.id.map);
        View zoomView = mapView.getZoomControls();
        LinearLayout myzoom = (LinearLayout) findViewById(R.id.zoom);
        myzoom.addView(zoomView);
        mapView.setStreetView(false);
        mapView.setBuiltInZoomControls(true);
        mapView.displayZoomControls(true);
        // Untuk mengambil lokasi user saat ini
        prefLocation = mContext.getSharedPreferences("mkul", 0);
        double latUser = Double.parseDouble(prefLocation.getString("userLat",
                "0"));
        double lonUser = Double.parseDouble(prefLocation.getString("userLon",
                "0"));
        gpUser = new GeoPoint((int) (latUser * 1E6), (int) (lonUser * 1E6));

        mapController = mapView.getController();

        TowerController rc = new TowerController(mContext);
        List<TowerModel> lsRm = rc.getAll();

        for (int i = 0; i < lsRm.size(); i++) {
            TowerModel poi = lsRm.get(i);

            lat = poi.getLat();
            lon = poi.getLon();
            name = poi.getName();
            alamat = poi.getAddress();

            String coordinates[] = {lat, lon};

            double lati = Double.parseDouble(coordinates[0]);
            double longi = Double.parseDouble(coordinates[1]);

            p = new GeoPoint((int) (lati * 1E6), (int) (longi * 1E6));

            List<Overlay> mapOverlays = mapView.getOverlays();
            int draw = R.drawable.marker;
            Drawable drawable = this.getResources().getDrawable(draw);
            MapOverlay itemizedoverlay = new MapOverlay(drawable,mContext,poi);
            OverlayItem overlayitem = new OverlayItem(p, name, alamat);
            itemizedoverlay.addOverlay(overlayitem);
            mapOverlays.add(itemizedoverlay);
        }
        mapController.animateTo(gpUser);
        mapController.setZoom(16); 
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

}

必须更改哪些代码?

0 个答案:

没有答案