と がありlistview
、ユーザーの位置(現在の緯度と経度)を取得onItemSelected
するために を呼び出します。このアクティビティにはレイアウトがありません。このアクティビティは、 から選択された項目の緯度と経度を取得し、両方のユーザーの位置をマークする別のアクティビティを自動的に呼び出します。マップ上のアイテムの場所。Activity
listview
これは、エミュレーターとSamsung Galaxy Aceでテストしていたときは問題なく動作しましたが、 Micromax A50とSony Xperiaでテストしているとクラッシュします。
悲しいことに、後の 2 つのデバイスのドライバーをインストールできないため、logcat を取得できません。
何がうまくいかなかったのか、誰でも推測できますか??
ユーザーの場所を見つけるための私のコードは次のとおりです。
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());
}
}
}