我有 mapActivity,我在其中注册了我的 MapView 小部件,并且我正在运行在后台检查位置数据的服务。我像这样通过 BroadcastReceiver 在 mapactivity 中启动我的服务
public class MainActivity extends MapActivity {
private MapView view;
protected void onCreate(Bundle savedInstanceState) {
view = (MapView) findViewById(R.id.themap);
view.setBuiltInZoomControls(true);
Intent in = new Intent();
MyReceiver locationRecvr = new MyReceiver();
locationRecvr.onReceive(getApplicationContext(), in);
}
......................
}
myReveiver.java
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "MyReceiver Started..",Toast.LENGTH_SHORT).show();
Log.v("Debug", "MyReceiver Started..");
Intent myIntent=new Intent(context, ServiceLocation.class);
context.startService(myIntent);
}
}
和这样的 myservice 和 LocationListener
public class ServiceLocation extends Service implements LocationListener {
......
.....
....
}
我的问题是位置更改时如何更改 mapview 上的位置如何在 onLocationchanged() 方法中获取 mapview 参考,或者如何将纬度和经度发送到 mapActivity。
提前致谢