【发布时间】:2016-05-19 18:08:44
【问题描述】:
我正在尝试使用我在一项活动中获得的位置数据在另一项活动中进行计算并传输我正在尝试使用 Intent 的数据。但是,当我尝试添加 Intent 时,我不断收到错误
'无法解析构造函数'
我尝试从中传递数据的活动如下所示:
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;
public class CurrentLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location)
{
if(location != null)
{
Double currentLat = location.getLatitude();
Double currentLong = location.getLongitude();
Log.e("Latitude :", "" + location.getLatitude());
Log.e("Longitude :", "" + location.getLongitude());
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("Lat", currentLat);
intent.putExtra("Long", currentLong);
CurrentLocationListener.this.startActivity(intent);
}
}
这是我尝试在其他活动中使用数据的地方:
public class MainActivity extends Activity implements SensorEventListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
parseButton.setOnClickListener(
new Button.OnClickListener()
{
public void onClick(View inputButtonView)
{
String latInputString = latFind.getText().toString();
String longInputString = longFind.getText().toString();
double latInputDouble = Double.parseDouble(latInputString);
double longInputDouble = Double.parseDouble(longInputString);
double dLon = (longInputDouble-currentLong);
double y = Math.sin(dLon) * Math.cos(latInputDouble);
double x = Math.cos(currentLat)
*Math.sin(latInputDouble) - Math.sin(currentLat)
*Math.cos(latInputDouble)*Math.cos(dLon);
double targetBearing = Math.toDegrees((Math.atan2(y, x)));
targetBearing = (360 - ((targetBearing + 360) % 360));
}
});
所以我要问的是:如何正确地将纬度和经度的 Double 数据从一项活动传输到另一项活动?
【问题讨论】:
-
我也在绞尽脑汁思考如何正确回调捆绑的数据
标签: android android-intent android-activity navigation double