加载地图在少数设备上崩溃

时间:2012-06-21 09:23:02

标签: android map geolocation samsung-mobile sony

我有listviewonItemSelected,会调用Activity来获取用户位置(他当前的 lat 和< strong> lng ),此活动没有布局,然后此活动自动调用另一个活动,该活动获得从{{1}中选择的项目的 lat lng 并标记地图上的用户位置和项目位置。

当我在模拟器三星Galaxy Ace 上进行测试时工作正常,但当我在崩溃时崩溃我正在测试 Micromax A50 Sony Xperia

可悲的是我无法安装后两个设备的驱动程序,因此我无法获得logcat 任何人都可以猜出可能出错的地方吗?

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

listview

和项目位置是:

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());
    }

}

1 个答案:

答案 0 :(得分:0)

也许这可以帮到你: Location Method Calls Crashes On Some Devices