将数据发送到MapActivity

时间:2016-04-14 19:16:28

标签: android google-maps

我有一些纬度和logtitute我想将这些发送到MapActivity是否有可能我做了很多方法但失败了

public void setdaata(View view){
    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("key", "value");
    Intent intent = new Intent(this, MapsActivity.class);
    intent.putExtra("map", item);
    startActivity(intent);




}

并在Mapacitivity中接收代码

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    Intent intent = getIntent();
    HashMap<String, String> hashMap = (HashMap<String, String>)intent.getSerializableExtra("map");
    Log.v("HashMapTest", hashMap.get("key"));
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

1 个答案:

答案 0 :(得分:1)

所以,也许你不需要这里的地图来发送两个简单的值:

试试这个:

Intent intent = new Intent(this, MapActivity.class);
intent.putExtra("longitude", mLongitude);
intent.putExtra("latitude", mLatitude);
startActivity(intent);

然后提取您的值:

Intent intent = getIntent();

double mLongitude = intent.getExtras().getDouble("longitude);
double mLatitude = intent.getExtras().getDouble("latitude");

现在你应该根据需要获得你的价值!!

我希望这可以帮到你!