2012-06-21 56 views
0

我有一个listviewonItemSelected,将调用Activity得到用户位置(他目前的LATLNG),这个活动有没有布局,那么这个活动会自动调用另一个活动latlnglistview中选择的项目,并在地图上标记用户位置和项目位置。载入地图崩溃

工作得很好当我在模拟器三星Galaxy王牌测试,但它崩溃当我Micromax的A50和索尼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()); 
     } 
    } 
} 
+0

“可悲的是,我无法安装后面的2个设备的驱动程序,所以我不能得到logcat。“ - 然后使用应用程序来阅读LogCat。 Play商店中有好几个,希望有一两个开源软件。 – CommonsWare

+0

您正在使用哪款Sony Xperia手机?我可能会得到你的司机。 Logcat肯定是需要调试的。 – Anup

+0

索尼Xperia X8 ...但我想Micromax A50的驱动程序..我在互联网上找不到...我一直在寻找它的过去4-5天:( –

回答