谷歌地图用异步,有什么不对?

时间:2015-05-04 10:08:51

标签: java android google-maps

我有一个异步任务,我试图将地图标记添加到Android中的谷歌地图。我设置了我的地图并使用以下方法调用异步任务:

class detail_objek

public void onClick(View v) {  
    Toast.makeText(getApplicationContext(), "anda memilih maps", Toast.LENGTH_LONG).show(); 
    Intent in = new Intent(v.getContext(), maps.class);
                in.putExtra("currentlatitude",filelatitude);
            in.putExtra("currentlongitude", filelongitude);
                startActivity(in);

}

我在此代码中遇到异步错误:

班级地图

public class maps extends FragmentActivity {
    String filelongitude,
            filelatitude;
    ProgressDialog pDialog;
    private GoogleMap mMap;
    private LatLng userLocation;
    Double destLatitude, destLongitude;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);

    initMap();

    Intent in = getIntent();
    filelatitude = in.getStringExtra("latitude");
    filelongitude = in.getStringExtra("longitude");

    new DownloadList().execute();
}

public class DownloadList extends AsyncTask<Void, Void, Void> {
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(maps.this);
        pDialog.setMessage("Tunggu Sebentar...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
    }

    protected Void doInBackground(Void... unused) {
        destLatitude = Double.parseDouble(filelatitude);
        destLongitude = Double.parseDouble(filelongitude);
        return null;
    }

    protected void onPostExecute(Void unused) {
        pDialog.dismiss();
        addMarkerToMap(new LatLng(destLatitude, destLongitude), false);
        searchLocation();
    }
}

地图一直在努力,直到现在;我没有做任何与代码相关的地图。

我尝试在Google控制台上重新生成调试密钥,更改权限等,但我没有想法。

1 个答案:

答案 0 :(得分:0)

filelatitude = in.getStringExtra("latitude");
filelongitude = in.getStringExtra("longitude");

当你需要一个双精灵时,你正试图从意图的额外中获取一个String。我假设in.putExtra("currentlatitude",filelatitude); filelatitude是双倍的。另一个错误是您指定了错误的密钥。你把额外的关键“currentlatitude”放在一边,试着用“纬度”来获取数据。

将您的代码更改为: filelatitude = in.getDoubleExtra("currentlatitude"); filelongitude = in.getDoubleExtra("currentlongitude");

P.S - 尝试将静态最终字段用于键