0

我有一个listviewand onItemSelected,将调用 anActivity来获取用户位置(他当前的latlng),此活动没有布局,然后此活动自动调用另一个活动,该活动获取从 中选择的项目的latlnglistview并标记用户位置和地图上的项目位置。

当我在EmulatorSamsung Galaxy Ace上进行测试时,它运行良好,但是当我在Micromax A50Sony Xperia上进行测试时它崩溃了。

可悲的是我无法安装后面2个设备的驱动程序,所以我无法获得logcat。
任何 1 都可以猜出可能出了什么问题?

我查找用户位置的代码是:

public class MyLocationActivity extends Activity implements LocationListener {
    private LocationManager mgr;
    private String best;
    public static double myLocationLatitude;
    public static double myLocationLongitude;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mgr = (LocationManager) getSystemService(LOCATION_SERVICE);

        dumpProviders();

        Criteria criteria = new Criteria();

        best = mgr.getBestProvider(criteria, true);
        Log.d("best provider", best);

        Location location = mgr.getLastKnownLocation(best);
        dumpLocation(location);

        /*Intent intent = new Intent(MyLocationActivity.this, ShowMapActivity.class);
        startActivity(intent);*/

        Intent intent = new Intent(MyLocationActivity.this, MapMarkerActivity.class);
        startActivity(intent);
        finish();
    }

    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
        dumpLocation(location);

    }

    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

    @Override
    protected void onPause() {

        super.onPause();
        mgr.removeUpdates(this);
    }

    @Override
    protected void onResume() {

        super.onResume();
        mgr.requestLocationUpdates(best, 15000, 1, this);
    }

    private void dumpLocation(Location l) {

        if (l == null) {

            myLocationLatitude = 0.0;
            myLocationLongitude = 0.0;
        } else {

            myLocationLatitude = l.getLatitude();
            myLocationLongitude = l.getLongitude();
        }
    }

    private void dumpProviders() {

        List<String> providers = mgr.getAllProviders();
        for (String p : providers) {

            dumpProviders(p);
        }
    }

    private void dumpProviders(String s) {

        LocationProvider info = mgr.getProvider(s);
        StringBuilder builder = new StringBuilder();
        builder.append("name: ").append(info.getName());
    }

}

项目位置是:

public class MapMarkerActivity extends MapActivity {

    private MapView map = null;
    private MyLocationOverlay me = null;
    private Drawable marker1;
    private Drawable marker2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.particular_entry);

        Button feedButton = (Button) findViewById(R.id.feedButton_particularEntry);
        feedButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {

                Intent intent = new Intent(MapMarkerActivity.this,
                        FeedListViewActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(intent);
            }
        });

        Button iWantButton = (Button) findViewById(R.id.iWantButton_particularEntry);
        iWantButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent intent = new Intent(MapMarkerActivity.this,
                        IWantActivity.class);
                startActivity(intent);
            }
        });

        Button shareButton = (Button) findViewById(R.id.shareButton_particularEntry);
        shareButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent intent = new Intent(MapMarkerActivity.this,
                        ShareActivity.class);
                startActivity(intent);
            }
        });

        Button profileButton = (Button) findViewById(R.id.profileButton_particularEntry);
        profileButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent intent = new Intent(MapMarkerActivity.this,
                        ProfileActivity.class);
                startActivity(intent);
            }
        });

        map = (MapView) findViewById(R.id.map);

        map.getController().setCenter(
                getPoint(FeedListViewActivity.lat, FeedListViewActivity.lng));
        map.getController().setZoom(13);
        map.setBuiltInZoomControls(true);

        marker1 = getResources().getDrawable(R.drawable.marker2);

        marker2 = getResources().getDrawable(R.drawable.marker1);

        marker1.setBounds(0, 0, marker1.getIntrinsicWidth(),
                marker1.getIntrinsicHeight());
        marker2.setBounds(0, 0, marker1.getIntrinsicWidth(),
                marker1.getIntrinsicHeight());

        map.getOverlays().add(new SitesOverlay(marker1));

        me = new MyLocationOverlay(this, map);
        map.getOverlays().add(me);
    }

    @Override
    public void onResume() {
        super.onResume();

        me.enableCompass();
    }

    @Override
    public void onPause() {
        super.onPause();

        me.disableCompass();
    }

    @Override
    protected boolean isRouteDisplayed() {
        return (false);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_S) {
            map.setSatellite(!map.isSatellite());
            return (true);
        } else if (keyCode == KeyEvent.KEYCODE_Z) {
            map.displayZoomControls(true);
            return (true);
        }

        return (super.onKeyDown(keyCode, event));
    }

    private GeoPoint getPoint(double lat, double lon) {
        return (new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0)));
    }

    public class SitesOverlay extends ItemizedOverlay<OverlayItem> {
        private List<OverlayItem> items = new ArrayList<OverlayItem>();

        public SitesOverlay(Drawable marker) {
            super(marker);

            boundCenterBottom(marker);

            OverlayItem oli1 = new OverlayItem(getPoint(
                    MyLocationActivity.myLocationLatitude,
                    MyLocationActivity.myLocationLongitude), "YL",
                    "Your Location");
            oli1.setMarker(marker2);
            items.add(oli1);

            OverlayItem oli2 = new OverlayItem(getPoint(
                    FeedListViewActivity.lat, FeedListViewActivity.lng), "SL",
                    "Store Location");
            oli2.setMarker(marker1);
            items.add(oli2);

            populate();
        }

        @Override
        protected OverlayItem createItem(int i) {
            return (items.get(i));
        }

        @Override
        protected boolean onTap(int i) {
            Toast.makeText(MapMarkerActivity.this, items.get(i).getSnippet(),
                    Toast.LENGTH_SHORT).show();

            return (true);
        }

        @Override
        public int size() {
            return (items.size());
        }
    }
}
4

1 回答 1

0

也许这可以帮助你: Location Method Calls Crashs On Some Devices

于 2012-07-09T18:26:18.373 回答