0

i have some latitude and logtitute i want to send these to MapActivity is it possible i did many ways but failled

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);




}

and receiving code in 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);
Naveed Abbas
  • 220
  • 3
  • 10

1 Answers1

1

So, perhaps you don't need a map here to send two simple values:

Try this:

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

Then to extract your values:

Intent intent = getIntent();

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

Now you should have your values as needed!!

I hope this helps you!

Eenvincible
  • 5,641
  • 2
  • 27
  • 46
  • sir but i have alot of values which i recieved through json this method i think work for just 2 values is there any way to send array to MApactivity – Naveed Abbas Apr 14 '16 at 19:49
  • The best approach here would then be to store your data in a local database and then simply go to the next activity and query your database simply and display the data to the user. That is what I would do – Eenvincible Apr 14 '16 at 19:53