要使用Mylocation.getMyLocation()获取gps的坐标而不是mapacitivity

时间:2012-04-23 22:03:42

标签: android gps mapactivity mylocationoverlay

我变得疯狂,因为我必须从mMyLocationOverlay.getMyLocation() ListActivity而不是MapActivity通过gps获得我的位置。 GetMyLocation需要我没有的上下文和mapview。我尝试使用mapActivity但我在" Caused by: java.lang.IllegalArgumentException: mapView == null "构造函数上获得运行时MyLocationOverlay()的错误。我发布了错误的代码:

public class ListDeals extends ListActivity
{   

private Events[] events;  
private MyLocationOverlay mMyLocationOverlay;//Riferimento al MyLocationOverlay
private GeoPoint myPoint = null;

@Override
public void onCreate(Bundle savedInstanceState) 
{
  super.onCreate(savedInstanceState);
  String type = this.getIntent().getStringExtra("type"); //legge cosa c'era scritto nell'intent per avere il dato necessario per fare la query al db

  setContentView(R.layout.list_view_x_deals);
  MapView mMapView = (MapView) findViewById(R.id.mapview);
  mMyLocationOverlay = new MyLocationOverlay(this, MyMapView.mapView);
  myPoint = mMyLocationOverlay.getMyLocation();

MyMapView.mapView是我在MapActivity中创建的“最终MapView”。

我哪里错了?

1 个答案:

答案 0 :(得分:1)

如果您没有MapView,则无法使用MapView内容。如果您希望采用该格式,请使用regular GPS api获取Location并将其转换为GeoPoint